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 30, 2020
1 parent 9bea1cc commit d5e64c9
Showing 1 changed file with 11 additions and 24 deletions.
35 changes: 11 additions & 24 deletions pandas/tests/series/methods/test_sort_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@
import pandas._testing as tm


@pytest.fixture
def sort_kind():
return ["quicksort", "mergesort", "heapsort", "stable"]


class TestSeriesSortIndex:
def test_sort_index_name(self, datetime_series):
result = datetime_series.sort_index(ascending=False)
Expand Down Expand Up @@ -104,18 +109,12 @@ 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):
def test_sort_index_kind(self, sort_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=sort_kind)
tm.assert_series_equal(expected_series, index_sorted_series)

def test_sort_index_na_position(self):
Expand Down Expand Up @@ -251,32 +250,20 @@ 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):
def test_sort_index_kind_key(self, sort_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)
tm.assert_series_equal(expected_series, index_sorted_series)

index_sorted_series = series.sort_index(kind="heapsort", key=sort_by_key)
index_sorted_series = series.sort_index(kind=sort_kind, key=sort_by_key)
tm.assert_series_equal(expected_series, index_sorted_series)

def test_sort_index_kind_neg_key(self):
def test_sort_index_kind_neg_key(self, sort_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=sort_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 d5e64c9

Please sign in to comment.