Skip to content

Commit 16bb784

Browse files
Damodara PudduDamodara Puddu
Damodara Puddu
authored and
Damodara Puddu
committed
TST: Added the new supported sorting algorithm stable to test
Addition to doc Fix PR: #38503 Implemented changes: Parameterized tests with addition of the newly supported sorting method stable from numpy 1.15.0
1 parent 9bea1cc commit 16bb784

File tree

1 file changed

+11
-24
lines changed

1 file changed

+11
-24
lines changed

pandas/tests/series/methods/test_sort_index.py

+11-24
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@
77
import pandas._testing as tm
88

99

10+
@pytest.fixture(params=["quicksort", "mergesort", "heapsort", "stable"])
11+
def sort_kind(request):
12+
return request.param
13+
14+
1015
class TestSeriesSortIndex:
1116
def test_sort_index_name(self, datetime_series):
1217
result = datetime_series.sort_index(ascending=False)
@@ -104,18 +109,12 @@ def test_sort_index_multiindex(self, level):
104109
res = s.sort_index(level=level, sort_remaining=False)
105110
tm.assert_series_equal(s, res)
106111

107-
def test_sort_index_kind(self):
112+
def test_sort_index_kind(self, sort_kind):
108113
# GH#14444 & GH#13589: Add support for sort algo choosing
109114
series = Series(index=[3, 2, 1, 4, 3], dtype=object)
110115
expected_series = Series(index=[1, 2, 3, 3, 4], dtype=object)
111116

112-
index_sorted_series = series.sort_index(kind="mergesort")
113-
tm.assert_series_equal(expected_series, index_sorted_series)
114-
115-
index_sorted_series = series.sort_index(kind="quicksort")
116-
tm.assert_series_equal(expected_series, index_sorted_series)
117-
118-
index_sorted_series = series.sort_index(kind="heapsort")
117+
index_sorted_series = series.sort_index(kind=sort_kind)
119118
tm.assert_series_equal(expected_series, index_sorted_series)
120119

121120
def test_sort_index_na_position(self):
@@ -251,32 +250,20 @@ def test_sort_index_key_int(self):
251250
result = series.sort_index(key=lambda x: 2 * x)
252251
tm.assert_series_equal(result, series)
253252

254-
def test_sort_index_kind_key(self, sort_by_key):
253+
def test_sort_index_kind_key(self, sort_kind, sort_by_key):
255254
# GH #14444 & #13589: Add support for sort algo choosing
256255
series = Series(index=[3, 2, 1, 4, 3], dtype=object)
257256
expected_series = Series(index=[1, 2, 3, 3, 4], dtype=object)
258257

259-
index_sorted_series = series.sort_index(kind="mergesort", key=sort_by_key)
260-
tm.assert_series_equal(expected_series, index_sorted_series)
261-
262-
index_sorted_series = series.sort_index(kind="quicksort", key=sort_by_key)
263-
tm.assert_series_equal(expected_series, index_sorted_series)
264-
265-
index_sorted_series = series.sort_index(kind="heapsort", key=sort_by_key)
258+
index_sorted_series = series.sort_index(kind=sort_kind, key=sort_by_key)
266259
tm.assert_series_equal(expected_series, index_sorted_series)
267260

268-
def test_sort_index_kind_neg_key(self):
261+
def test_sort_index_kind_neg_key(self, sort_kind):
269262
# GH #14444 & #13589: Add support for sort algo choosing
270263
series = Series(index=[3, 2, 1, 4, 3], dtype=object)
271264
expected_series = Series(index=[4, 3, 3, 2, 1], dtype=object)
272265

273-
index_sorted_series = series.sort_index(kind="mergesort", key=lambda x: -x)
274-
tm.assert_series_equal(expected_series, index_sorted_series)
275-
276-
index_sorted_series = series.sort_index(kind="quicksort", key=lambda x: -x)
277-
tm.assert_series_equal(expected_series, index_sorted_series)
278-
279-
index_sorted_series = series.sort_index(kind="heapsort", key=lambda x: -x)
266+
index_sorted_series = series.sort_index(kind=sort_kind, key=lambda x: -x)
280267
tm.assert_series_equal(expected_series, index_sorted_series)
281268

282269
def test_sort_index_na_position_key(self, sort_by_key):

0 commit comments

Comments
 (0)