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

Fix type annotations in pandas.core.indexes.period #26518

Merged
merged 3 commits into from
May 29, 2019
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions mypy.ini
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,3 @@ ignore_errors=True

[mypy-pandas.core.indexes.datetimelike]
ignore_errors=True

[mypy-pandas.core.indexes.period]
ignore_errors=True
4 changes: 2 additions & 2 deletions pandas/core/indexes/period.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ class PeriodIndex(DatetimeIndexOpsMixin, Int64Index, PeriodDelegateMixin):

Parameters
----------
data : array-like (1-dimensional), optional
data : array-like (1-dimensional) - PeriodArray, optional
Copy link
Contributor

Choose a reason for hiding this comment

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

this is not very clear, can you enumerate a bit

1d int np.ndarray or PeriodArray, optional

Copy link
Contributor Author

Choose a reason for hiding this comment

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

data : array-like (1-dimensional integer np.ndarray or PeriodArray), optional, looks good?

Copy link
Contributor

Choose a reason for hiding this comment

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

use 1d

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Okay, I will get it done after a few hours

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@jreback I have fixed it, sorry for the delay.

Optional period-like data to construct index with
copy : bool
Make a copy of input ndarray
Expand Down Expand Up @@ -168,7 +168,7 @@ class PeriodIndex(DatetimeIndexOpsMixin, Int64Index, PeriodDelegateMixin):
_is_numeric_dtype = False
_infer_as_myclass = True

_data = None # type: PeriodArray
_data = None
Copy link
Member

Choose a reason for hiding this comment

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

So what is this getting inferred as now?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@WillAyd Inferred type is None, which is not correct, but putting the actual type is almost impossible. Because the type of _data in parent/sibling classes (e.g. in class Index, DatetimeIndexOpsMixin, etc.) is different. If we want to properly type this we need to create a type ArrayLike(I guess) in pandas._typing which can contain all possible type for _data then use it everywhere. But I don't know how many of these arraylike types(PeriodArray, DatetimeLikeArray, etc) are there, so someone will have to tell me how to find that, maybe @gfyoung can help with that.
If you want something like this, I would suggest doing that in a separate issue & PR as a lot of files will be changed as _data is in like 100 different files.

Copy link
Member

Choose a reason for hiding this comment

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

We already have that in the typing module - did that not work?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Okay, we do have array like in _typing, my bad, didn't saw that.
I think _typing.AnyArrayLike is what we need. Mypy will be happy with whatever type I put for _data, so someone should confirm that AnyArrayLike is the proper type to use for _data, and I will type _data in every class.

Copy link
Member

Choose a reason for hiding this comment

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

Yea I think that should work here


_engine_type = libindex.PeriodEngine

Expand Down