Skip to content
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

TYP: alias IndexLabel without Optional #36401

Merged
merged 2 commits into from
Sep 17, 2020
Merged

Conversation

ivanovmg
Copy link
Member

@ivanovmg ivanovmg commented Sep 16, 2020

  • closes #xxxx
  • tests added / passed
  • passes black pandas
  • passes git diff upstream/master -u -- "*.py" | flake8 --diff
  • whatsnew entry

Previously in _typing.py we had the alias IndexLabel, which contained Optional.
The present PR eliminates Optional from the alias, but adds it in the code where necessary.

Related to the issue raised by @simonjayhawkins in #36046 (comment)

@ivanovmg ivanovmg added the Typing type annotations, mypy/pyright type checking label Sep 16, 2020
Copy link
Member

@simonjayhawkins simonjayhawkins left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @ivanovmg lgtm pending green

@simonjayhawkins simonjayhawkins added this to the 1.2 milestone Sep 16, 2020
@ivanovmg
Copy link
Member Author

Travis CI failed at miniconda build. Can anyone restart?

@rhshadrach
Copy link
Member

Since IndexLabel can be a Label, and Label = Optional[Hashable], isn't Optional[IndexLabel] the same as IndexLabel?

@jreback
Copy link
Contributor

jreback commented Sep 17, 2020

lgtm. @simonjayhawkins can you address @rhshadrach question.

@simonjayhawkins
Copy link
Member

Since IndexLabel can be a Label, and Label = Optional[Hashable], isn't Optional[IndexLabel] the same as IndexLabel?

for typing, yes. just as Union[int, float] is equivalent to float and the Optional in function signatures could be implicit. We do this for clarity and consistency.

However, the actual convention that we should eventually adopt maybe determined by the outcome of #28585 and #33025.

If we go the route of showing the aliases in the docs ( scikit-learn/scikit-learn#16705 (comment) and numpy/numpydoc#196 related), having the Optional maybe preferable.

@jreback jreback merged commit d4947a9 into pandas-dev:master Sep 17, 2020
@jreback
Copy link
Contributor

jreback commented Sep 17, 2020

thanks @ivanovmg

rhshadrach pushed a commit to rhshadrach/pandas that referenced this pull request Sep 17, 2020
kesmit13 pushed a commit to kesmit13/pandas that referenced this pull request Nov 2, 2020
@ivanovmg ivanovmg deleted the typing/csvs branch December 3, 2020 07:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Typing type annotations, mypy/pyright type checking
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants