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 19d04d6
Showing 1 changed file with 14 additions and 24 deletions.
38 changes: 14 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,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", sort_kind)
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 +251,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", sort_kind)
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)
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=kind, 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", sort_kind)
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 19d04d6

Please sign in to comment.