-
-
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
Conversation
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.
Looks good. Can you add a whatsnew
entry for v1.2 ?
I have added the v1.2 whatsnew entry , please take a look |
doc/source/whatsnew/v1.2.0.rst
Outdated
@@ -352,7 +352,7 @@ Indexing | |||
- Bug in :meth:`PeriodIndex.get_loc` incorrectly raising ``ValueError`` on non-datelike strings instead of ``KeyError``, causing similar errors in :meth:`Series.__geitem__`, :meth:`Series.__contains__`, and :meth:`Series.loc.__getitem__` (:issue:`34240`) | |||
- Bug in :meth:`Index.sort_values` where, when empty values were passed, the method would break by trying to compare missing values instead of pushing them to the end of the sort order. (:issue:`35584`) | |||
- Bug in :meth:`Index.get_indexer` and :meth:`Index.get_indexer_non_unique` where int64 arrays are returned instead of intp. (:issue:`36359`) | |||
- | |||
- Bug in :meth:`Index.sortlevel` where, add the check of ascending parameter in the sortlevel method, only allow bool value and single bool value list. (:issue:`32334`) |
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.
Better to say
Bug in :meth:`DataFrame.sort_index` where parameter ascending passed as a list on a single level index gives wrong result. (:issue:`32334`)
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.
whatsnew has been adjusted, please take a look
thanks @BEANNAN |
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.
@Dr-Irv ideally this would have had more review
@@ -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 comment
The 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 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 comment
The 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)
@@ -1515,6 +1515,20 @@ def sortlevel(self, level=None, ascending=True, sort_remaining=None): | |||
------- | |||
Index | |||
""" | |||
if not isinstance(ascending, (list, bool)): |
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
…ndas-dev#36767) * BUG: Index sortlevel ascending add type checking pandas-dev#32334 * DOC: add v1.2 whatsnew entry pandas-dev#32334 * BUG: adjust judgment conditions, len(ascending) > 1 => len(ascending) != 1 * DOC: adjustment whatsnew Co-authored-by: beanan <fanjianan916@hotmail.com>
black pandas
git diff upstream/master -u -- "*.py" | flake8 --diff
Add the check of ascending parameter in the sortlevel method, only allow bool value and single bool value list
cc @Dr-Irv