From 27c15ae3f8ccc53d0b91603f6afd640c5aa2e4b4 Mon Sep 17 00:00:00 2001 From: Damodara Puddu Date: Wed, 16 Dec 2020 09:19:11 +0000 Subject: [PATCH] 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 --- .../tests/series/methods/test_sort_index.py | 33 +++++-------------- 1 file changed, 9 insertions(+), 24 deletions(-) diff --git a/pandas/tests/series/methods/test_sort_index.py b/pandas/tests/series/methods/test_sort_index.py index 6c6be1506255a..60e3e75af8f34 100644 --- a/pandas/tests/series/methods/test_sort_index.py +++ b/pandas/tests/series/methods/test_sort_index.py @@ -104,18 +104,13 @@ def test_sort_index_multiindex(self, level): res = s.sort_index(level=level, sort_remaining=False) tm.assert_series_equal(s, res) - def test_sort_index_kind(self): + @pytest.mark.parametrize("kind", ["quicksort", "mergesort", "heapsort", "stable"]) + def test_sort_index_kind(self, kind): # GH#14444 & GH#13589: Add support for sort algo choosing series = Series(index=[3, 2, 1, 4, 3], dtype=object) expected_series = Series(index=[1, 2, 3, 3, 4], dtype=object) - index_sorted_series = series.sort_index(kind="mergesort") - tm.assert_series_equal(expected_series, index_sorted_series) - - index_sorted_series = series.sort_index(kind="quicksort") - tm.assert_series_equal(expected_series, index_sorted_series) - - index_sorted_series = series.sort_index(kind="heapsort") + index_sorted_series = series.sort_index(kind=kind) tm.assert_series_equal(expected_series, index_sorted_series) def test_sort_index_na_position(self): @@ -251,32 +246,22 @@ def test_sort_index_key_int(self): result = series.sort_index(key=lambda x: 2 * x) tm.assert_series_equal(result, series) - def test_sort_index_kind_key(self, sort_by_key): + @pytest.mark.parametrize("kind", ["quicksort", "mergesort", "heapsort", "stable"]) + def test_sort_index_kind_key(self, kind, sort_by_key): # GH #14444 & #13589: Add support for sort algo choosing series = Series(index=[3, 2, 1, 4, 3], dtype=object) expected_series = Series(index=[1, 2, 3, 3, 4], dtype=object) - index_sorted_series = series.sort_index(kind="mergesort", key=sort_by_key) - tm.assert_series_equal(expected_series, index_sorted_series) - - index_sorted_series = series.sort_index(kind="quicksort", key=sort_by_key) + index_sorted_series = series.sort_index(kind=kind, key=sort_by_key) tm.assert_series_equal(expected_series, index_sorted_series) - index_sorted_series = series.sort_index(kind="heapsort", key=sort_by_key) - tm.assert_series_equal(expected_series, index_sorted_series) - - def test_sort_index_kind_neg_key(self): + @pytest.mark.parametrize("kind", ["quicksort", "mergesort", "heapsort", "stable"]) + def test_sort_index_kind_neg_key(self, kind): # GH #14444 & #13589: Add support for sort algo choosing series = Series(index=[3, 2, 1, 4, 3], dtype=object) expected_series = Series(index=[4, 3, 3, 2, 1], dtype=object) - index_sorted_series = series.sort_index(kind="mergesort", key=lambda x: -x) - tm.assert_series_equal(expected_series, index_sorted_series) - - index_sorted_series = series.sort_index(kind="quicksort", key=lambda x: -x) - tm.assert_series_equal(expected_series, index_sorted_series) - - index_sorted_series = series.sort_index(kind="heapsort", key=lambda x: -x) + index_sorted_series = series.sort_index(kind=kind, key=lambda x: -x) tm.assert_series_equal(expected_series, index_sorted_series) def test_sort_index_na_position_key(self, sort_by_key):