Skip to content

Commit 9ebdbb2

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 4e01bcf commit 9ebdbb2

File tree

1 file changed

+9
-24
lines changed

1 file changed

+9
-24
lines changed

pandas/tests/series/methods/test_sort_index.py

+9-24
Original file line numberDiff line numberDiff line change
@@ -104,18 +104,13 @@ def test_sort_index_multiindex(self, level):
104104
res = s.sort_index(level=level, sort_remaining=False)
105105
tm.assert_series_equal(s, res)
106106

107-
def test_sort_index_kind(self):
107+
@pytest.mark.parametrize("kind", ["quicksort", "mergesort", "heapsort", "stable"])
108+
def test_sort_index_kind(self, kind):
108109
# GH#14444 & GH#13589: Add support for sort algo choosing
109110
series = Series(index=[3, 2, 1, 4, 3], dtype=object)
110111
expected_series = Series(index=[1, 2, 3, 3, 4], dtype=object)
111112

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")
113+
index_sorted_series = series.sort_index(kind=kind)
119114
tm.assert_series_equal(expected_series, index_sorted_series)
120115

121116
def test_sort_index_na_position(self):
@@ -251,32 +246,22 @@ def test_sort_index_key_int(self):
251246
result = series.sort_index(key=lambda x: 2 * x)
252247
tm.assert_series_equal(result, series)
253248

254-
def test_sort_index_kind_key(self, sort_by_key):
249+
@pytest.mark.parametrize("kind", ["quicksort", "mergesort", "heapsort", "stable"])
250+
def test_sort_index_kind_key(self, kind, sort_by_key):
255251
# GH #14444 & #13589: Add support for sort algo choosing
256252
series = Series(index=[3, 2, 1, 4, 3], dtype=object)
257253
expected_series = Series(index=[1, 2, 3, 3, 4], dtype=object)
258254

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)
255+
index_sorted_series = series.sort_index(kind=kind, key=sort_by_key)
263256
tm.assert_series_equal(expected_series, index_sorted_series)
264257

265-
index_sorted_series = series.sort_index(kind="heapsort", key=sort_by_key)
266-
tm.assert_series_equal(expected_series, index_sorted_series)
267-
268-
def test_sort_index_kind_neg_key(self):
258+
@pytest.mark.parametrize("kind", ["quicksort", "mergesort", "heapsort", "stable"])
259+
def test_sort_index_kind_neg_key(self, kind):
269260
# GH #14444 & #13589: Add support for sort algo choosing
270261
series = Series(index=[3, 2, 1, 4, 3], dtype=object)
271262
expected_series = Series(index=[4, 3, 3, 2, 1], dtype=object)
272263

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)
264+
index_sorted_series = series.sort_index(kind=kind, key=lambda x: -x)
280265
tm.assert_series_equal(expected_series, index_sorted_series)
281266

282267
def test_sort_index_na_position_key(self, sort_by_key):

0 commit comments

Comments
 (0)