8000 API: Change default axis argument for argsort · numpy/numpy@4d30cff · GitHub
[go: up one dir, main page]

10000 Skip to content

Commit 4d30cff

Browse files
committed
API: Change default axis argument for argsort
Now matches: * its own documentation * everything else Fixes #8701
1 parent 1075c1d commit 4d30cff

File tree

2 files changed

+2
-61
lines changed

2 files changed

+2
-61
lines changed

numpy/ma/core.py

Lines changed: 2 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -93,33 +93,6 @@
9393
class MaskedArrayFutureWarning(FutureWarning):
9494
pass
9595

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-
12396

12497
def doc_note(initialdoc, note):
12598
"""
@@ -5255,7 +5228,7 @@ def round(self, decimals=0, out=None):
52555228
out.__setmask__(self._mask)
52565229
return out
52575230

5258-
def argsort(self, axis=np._NoValue, kind='quicksort', order=None,
5231+
def argsort(self, axis=-1, kind='quicksort', order=None,
52595232
endwith=True, fill_value=None):
52605233
"""
52615234
Return an ndarray of indices that sort the array along the
@@ -5311,8 +5284,6 @@ def argsort(self, axis=np._NoValue, kind='quicksort', order=None,
53115284
53125285
"""
53135286

5314-
axis = _deprecate_argsort_axis(self, axis)
5315-
53165287
if fill_value is None:
53175288
if endwith:
53185289
# nan > inf
@@ -6532,10 +6503,9 @@ def power(a, b, third=None):
65326503
argmin = _frommethod('argmin')
65336504
argmax = _frommethod('argmax')
65346505

6535-
def argsort(a, axis=np._NoValue, kind='quicksort', order=None, endwith=True, fill_value=None):
6506+
def argsort(a, axis=-1, kind='quicksort', order=None, endwith=True, fill_value=None):
65366507
"Function version of the eponymous method."
65376508
a = np.asanyarray(a)
6538-
axis = _deprecate_argsort_axis(a, axis)
65396509

65406510
if isinstance(a, MaskedArray):
65416511
return a.argsort(axis=axis, kind=kind, order=order,

numpy/ma/tests/test_deprecations.py

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -8,34 +8,5 @@
88
from numpy.ma.testutils import assert_equal
99

1010

11-
class TestArgsort(TestCase):
12-
""" gh-8701 """
13-
def _test_base(self, argsort, cls):
14-
arr_0d = np.array(1).view(cls)
15-
argsort(arr_0d)
16-
17-
arr_1d = np.array([1, 2, 3]).view(cls)
18-
argsort(arr_1d)
19-
20-
# argsort has a bad default for >1d arrays
21-
arr_2d = np.array([[1, 2], [3, 4]]).view(cls)
22-
result = assert_warns(
23-
np.ma.core.MaskedArrayFutureWarning, argsort, arr_2d)
24-
assert_equal(result, argsort(arr_2d, axis=None))
25-
26-
# should be no warnings for explictly specifiying it
27-
argsort(arr_2d, axis=None)
28-
argsort(arr_2d, axis=-1)
29-
30-
def test_function_ndarray(self):
31-
return self._test_base(np.ma.argsort, np.ndarray)
32-
33-
def test_function_maskedarray(self):
34-
return self._test_base(np.ma.argsort, np.ma.MaskedArray)
35-
36-
def test_method(self):
37-
return self._test_base(np.ma.MaskedArray.argsort, np.ma.MaskedArray)
38-
39-
4011
if __name__ == "__main__":
4112
run_module_suite()

0 commit comments

Comments
 (0)
0