summaryrefslogtreecommitdiff
path: root/numpy/ma
diff options
context:
space:
mode:
authorJulian Taylor <juliantaylor108@gmail.com>2018-03-31 10:48:41 +0200
committerGitHub <noreply@github.com>2018-03-31 10:48:41 +0200
commit256c6fcd5842c3b9aa897f37c868ba8f0c67b26c (patch)
treec80ac82a812d9767a1da21af84124d4d9dc23c95 /numpy/ma
parent7fd2a3931021fecd00a8c3d98230c2f2bf78bb46 (diff)
parent4a2891748ab9ac8cafd7aaef10222c761e96f892 (diff)
downloadnumpy-256c6fcd5842c3b9aa897f37c868ba8f0c67b26c.tar.gz
Merge pull request #10786 from lakshayg/stablesort
ENH: Add "stablesort" option to inp.sort as an alias for "mergesort".
Diffstat (limited to 'numpy/ma')
-rw-r--r--numpy/ma/core.py4
-rw-r--r--numpy/ma/tests/test_core.py6
2 files changed, 8 insertions, 2 deletions
diff --git a/numpy/ma/core.py b/numpy/ma/core.py
index 5f53dfdae..91cf8ed0f 100644
--- a/numpy/ma/core.py
+++ b/numpy/ma/core.py
@@ -5317,7 +5317,7 @@ class MaskedArray(ndarray):
originally intended.
Until then, the axis should be given explicitly when
``arr.ndim > 1``, to avoid a FutureWarning.
- kind : {'quicksort', 'mergesort', 'heapsort'}, optional
+ kind : {'quicksort', 'mergesort', 'heapsort', 'stable'}, optional
Sorting algorithm.
order : list, optional
When `a` is an array with fields defined, this argument specifies
@@ -5468,7 +5468,7 @@ class MaskedArray(ndarray):
axis : int, optional
Axis along which to sort. If None, the array is flattened before
sorting. The default is -1, which sorts along the last axis.
- kind : {'quicksort', 'mergesort', 'heapsort'}, optional
+ kind : {'quicksort', 'mergesort', 'heapsort', 'stable'}, optional
Sorting algorithm. Default is 'quicksort'.
order : list, optional
When `a` is a structured array, this argument specifies which fields
diff --git a/numpy/ma/tests/test_core.py b/numpy/ma/tests/test_core.py
index 4c6bb2b42..ff1e087b5 100644
--- a/numpy/ma/tests/test_core.py
+++ b/numpy/ma/tests/test_core.py
@@ -3200,6 +3200,12 @@ class TestMaskedArrayMethods(object):
assert_equal(sortedx._data, [1, 2, -2, -1, 0])
assert_equal(sortedx._mask, [1, 1, 0, 0, 0])
+ def test_stable_sort(self):
+ x = array([1, 2, 3, 1, 2, 3], dtype=np.uint8)
+ expected = array([0, 3, 1, 4, 2, 5])
+ computed = argsort(x, kind='stable')
+ assert_equal(computed, expected)
+
def test_argsort_matches_sort(self):
x = array([1, 4, 2, 3], mask=[0, 1, 0, 0], dtype=np.uint8)