-
-
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
Changes from 2 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 |
---|---|---|
|
@@ -15,6 +15,7 @@ | |
Optional, | ||
Tuple, | ||
Type, | ||
Union, | ||
) | ||
import warnings | ||
|
||
|
@@ -2981,11 +2982,11 @@ def sort_index( | |
self, | ||
axis=0, | ||
level=None, | ||
ascending=True, | ||
inplace=False, | ||
kind="quicksort", | ||
na_position="last", | ||
sort_remaining=True, | ||
ascending: Union[bool, List[bool]] = True, | ||
inplace: bool = False, | ||
kind: str = "quicksort", | ||
na_position: str = "last", | ||
sort_remaining: bool = True, | ||
ignore_index: bool = False, | ||
): | ||
""" | ||
|
@@ -3000,8 +3001,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 commentThe 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 commentThe 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 |
||
Sort ascending vs. descending. When the index is a MultiIndex the | ||
sort direction can be controlled for each level individually. | ||
inplace : bool, default False | ||
If True, perform operation in-place. | ||
kind : {'quicksort', 'mergesort', 'heapsort'}, default 'quicksort' | ||
|
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)