Skip to content

Conversation

@dsaxton
Copy link
Contributor

@dsaxton dsaxton commented Feb 11, 2020

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
Copy link
Member

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?

Copy link
Contributor Author

@dsaxton dsaxton Feb 12, 2020

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?

Copy link
Member

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?

Copy link
Contributor Author

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?

Copy link
Member

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

@WillAyd WillAyd added Docs Typing type annotations, mypy/pyright type checking labels Feb 12, 2020
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
Copy link
Member

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?

Copy link
Contributor Author

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

@dsaxton
Copy link
Contributor Author

dsaxton commented Feb 18, 2020

@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

@WillAyd WillAyd added this to the 1.1 milestone Feb 19, 2020
@WillAyd
Copy link
Member

WillAyd commented Feb 19, 2020

Yea would be nice to get the typing figured out, but OK for another day

@WillAyd WillAyd merged commit 0c107bd into pandas-dev:master Feb 19, 2020
@WillAyd
Copy link
Member

WillAyd commented Feb 19, 2020

Thanks @dsaxton

@dsaxton dsaxton deleted the doc-sort-idx branch February 19, 2020 01:36
roberthdevries pushed a commit to roberthdevries/pandas that referenced this pull request Mar 2, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Docs Typing type annotations, mypy/pyright type checking

Projects

None yet

Development

Successfully merging this pull request may close these issues.

MultiLevelIndex sort_index already does support ascending as a list of booleans

4 participants