Skip to content

Test that using a tuple or list for parameter ascending of sort_index is the same #43963

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Oct 16, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions pandas/tests/frame/methods/test_sort_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -785,6 +785,48 @@ def test_sort_index_use_inf_as_na(self):
result = expected.sort_index()
tm.assert_frame_equal(result, expected)

@pytest.mark.parametrize(
"ascending",
[(True, False), [True, False]],
)
def test_sort_index_ascending_tuple(self, ascending):
df = DataFrame(
{
"legs": [4, 2, 4, 2, 2],
},
index=MultiIndex.from_tuples(
[
("mammal", "dog"),
("bird", "duck"),
("mammal", "horse"),
("bird", "penguin"),
("mammal", "kangaroo"),
],
names=["class", "animal"],
),
)

# parameter `ascending`` is a tuple
result = df.sort_index(level=(0, 1), ascending=ascending)

expected = DataFrame(
{
"legs": [2, 2, 2, 4, 4],
},
index=MultiIndex.from_tuples(
[
("bird", "penguin"),
("bird", "duck"),
("mammal", "kangaroo"),
("mammal", "horse"),
("mammal", "dog"),
],
names=["class", "animal"],
),
)

tm.assert_frame_equal(result, expected)


class TestDataFrameSortIndexKey:
def test_sort_multi_index_key(self):
Expand Down