-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
DOC: Update sort_index docs #31898
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
DOC: Update sort_index docs #31898
Conversation
dsaxton
commented
Feb 11, 2020
- closes MultiLevelIndex sort_index already does support ascending as a list of booleans #31880
@@ -4989,8 +4989,9 @@ def sort_index( | |||
and 1 identifies the columns. | |||
level : int or level name or list of ints or list of level names | |||
If not None, sort on values in specified index level(s). | |||
ascending : bool, default True | |||
Sort ascending vs. descending. | |||
ascending : bool or list of bools, default True |
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.
Can you update the annotation for this function to reflect this?
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.
So originally I had given it a Union type but mypy complained because here the ascending argument seemingly has to be a singleton bool: https://github.com/pandas-dev/pandas/blob/master/pandas/core/frame.py#L5055. I guess this is unavoidable because it has no way of knowing that it shouldn't get here when ascending is a list?
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.
Wouldn't that conflict with the documentation updates?
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.
Hmm, I think it's okay since it "can" accept a list of bools, just conditional on the index being a MultiIndex?
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.
Not sure - looks like this works (probably shouldn't)
>>> pd.DataFrame([[1]]).sort_index(ascending=[True, False, True])
0
0 1
@@ -3000,8 +3000,9 @@ def sort_index( | |||
Axis to direct sorting. This can only be 0 for Series. | |||
level : int, optional | |||
If not None, sort on values in specified index level(s). | |||
ascending : bool, default true | |||
Sort ascending vs. descending. | |||
ascending : bool or list of bools, default True |
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.
if list of bools is allowed, should that show up in the annotation?
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.
See the discussion with WillAyd above; mypy doesn't seem to like that because nargsort
gets called when we don't have a MultiIndex and it expects a single bool
@WillAyd Good to merge or were there changes you'd like me to make? Not sure if there's a "nice" way to get around the mypy annoyance |
Yea would be nice to get the typing figured out, but OK for another day |
Thanks @dsaxton |