-
-
Notifications
You must be signed in to change notification settings - Fork 18.2k
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
BUG: Index sortlevel ascending add type checking #32334 #36767
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2222,6 +2222,31 @@ def test_contains_method_removed(self, index): | |
with pytest.raises(AttributeError, match=msg): | ||
index.contains(1) | ||
|
||
def test_sortlevel(self): | ||
index = pd.Index([5, 4, 3, 2, 1]) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we generally add the issue number here as a comment |
||
with pytest.raises(Exception, match="ascending must be a single bool value or"): | ||
index.sortlevel(ascending="True") | ||
|
||
with pytest.raises( | ||
Exception, match="ascending must be a list of bool values of length 1" | ||
): | ||
index.sortlevel(ascending=[True, True]) | ||
|
||
with pytest.raises(Exception, match="ascending must be a bool value"): | ||
index.sortlevel(ascending=["True"]) | ||
|
||
expected = pd.Index([1, 2, 3, 4, 5]) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this should be 2 tests, one for the exceptions, one for the working cases (which could be parameterized) |
||
result = index.sortlevel(ascending=[True]) | ||
tm.assert_index_equal(result[0], expected) | ||
|
||
expected = pd.Index([1, 2, 3, 4, 5]) | ||
result = index.sortlevel(ascending=True) | ||
tm.assert_index_equal(result[0], expected) | ||
|
||
expected = pd.Index([5, 4, 3, 2, 1]) | ||
result = index.sortlevel(ascending=False) | ||
tm.assert_index_equal(result[0], expected) | ||
|
||
|
||
class TestMixedIntIndex(Base): | ||
# Mostly the tests from common.py for which the results differ | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
these should be checked at a much lower level, where they are used; the reason these are fairly generic things not specific to Index in this case