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 1 commit
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
16 changes: 16 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,22 @@ def test_sort_index_use_inf_as_na(self):
result = expected.sort_index()
tm.assert_frame_equal(result, expected)

def test_sort_index_ascending_tuple(self):
df = DataFrame(
{
"animal": ["dog", "duck", "horse", "penguin", "kangaroo"],
"legs": [4, 2, 4, 2, 2],
"class": ["mammal", "bird", "mammal", "bird", "mammal"],
}
)

df.set_index(["class", "animal"], inplace=True)

sorted1 = df.sort_index(level=(0, 1), ascending=[True, False])
sorted2 = df.sort_index(level=(0, 1), ascending=(True, False))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please define index directly without set_index and define expected explicitly. Also parametrize over list and tuple. Please call sorted1 or sorted2 result

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@phofl Thank you, please let me know if I addressed all the changes you requested in my last commit.


tm.assert_frame_equal(sorted1, sorted2)


class TestDataFrameSortIndexKey:
def test_sort_multi_index_key(self):
Expand Down