|
93 | 93 | class MaskedArrayFutureWarning(FutureWarning):
|
94 | 94 | pass
|
95 | 95 |
|
| 96 | +def _deprecate_argsort_axis(arr, axis): |
| 97 | + """ |
| 98 | + Takes the array argsort was called upon, and the axis argument |
| 99 | + it was called with. |
| 100 | +
|
| 101 | + np.ma.argsort has a long-term bug where the default of the axis argument |
| 102 | + is wrong (gh-8701), which now must be kept for backwards compatibiity. |
| 103 | + Thankfully, this only makes a difference when arrays are 2- or more- |
| 104 | + dimensional, so we only need a warning then. |
| 105 | + """ |
| 106 | + if axis is np._NoValue: |
| 107 | + if arr.ndim <= 1: |
| 108 | + # no warning needed - switch to -1 to avoid surprising subclasses |
| 109 | + return -1 |
| 110 | + else: |
| 111 | + # 2017-04-10, numpy 1.13.0 |
| 112 | + warnings.warn( |
| 113 | + "Unlike np.argsort, np.sort, np.ma.sort, and the " |
| 114 | + "documentation for this function, the default is " |
| 115 | + "axis=None, not axis=-1. In future, the default will be " |
| 116 | + "-1. To squash this warning, specify the axis argument " |
| 117 | + "explicitly.", |
| 118 | + MaskedArrayFutureWarning, stacklevel=2) |
| 119 | + return None |
| 120 | + else: |
| 121 | + return axis |
| 122 | + |
96 | 123 |
|
97 | 124 | def doc_note(initialdoc, note):
|
98 | 125 | """
|
@@ -5228,7 +5255,7 @@ def round(self, decimals=0, out=None):
|
5228 | 5255 | out.__setmask__(self._mask)
|
5229 | 5256 | return out
|
5230 | 5257 |
|
5231 |
| - def argsort(self, axis=None, kind='quicksort', order=None, |
| 5258 | + def argsort(self, axis=np._NoValue, kind='quicksort', order=None, |
5232 | 5259 | endwith=True, fill_value=None):
|
5233 | 5260 | """
|
5234 | 5261 | Return an ndarray of indices that sort the array along the
|
@@ -5284,6 +5311,8 @@ def argsort(self, axis=None, kind='quicksort', order=None,
|
5284 | 5311 |
|
5285 | 5312 | """
|
5286 | 5313 |
|
| 5314 | + axis = _deprecate_argsort_axis(self, axis) |
| 5315 | + |
5287 | 5316 | if fill_value is None:
|
5288 | 5317 | if endwith:
|
5289 | 5318 | # nan > inf
|
@@ -6503,9 +6532,10 @@ def power(a, b, third=None):
|
6503 | 6532 | argmin = _frommethod('argmin')
|
6504 | 6533 | argmax = _frommethod('argmax')
|
6505 | 6534 |
|
6506 |
| -def argsort(a, axis=None, kind='quicksort', order=None, endwith=True, fill_value=None): |
| 6535 | +def argsort(a, axis=np._NoValue, kind='quicksort', order=None, endwith=True, fill_value=None): |
6507 | 6536 | "Function version of the eponymous method."
|
6508 | 6537 | a = np.asanyarray(a)
|
| 6538 | + axis = _deprecate_argsort_axis(a, axis) |
6509 | 6539 |
|
6510 | 6540 | if isinstance(a, MaskedArray):
|
6511 | 6541 | return a.argsort(axis=axis, kind=kind, order=order,
|
|
0 commit comments