Skip to content

Commit

Permalink
TST: Added the new supported sorting algorithm stable to test
Browse files Browse the repository at this point in the history
Addition to doc Fix PR: #38503

Implemented changes:
Parameterized tests with addition of the newly supported sorting method stable from numpy 1.15.0
  • Loading branch information
Damodara Puddu authored and Damodara Puddu committed Dec 16, 2020
1 parent 3f4d172 commit 27c15ae
Showing 1 changed file with 9 additions and 24 deletions.
33 changes: 9 additions & 24 deletions pandas/tests/series/methods/test_sort_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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):
Expand Down

0 comments on commit 27c15ae

Please sign in to comment.