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

Conversation

vaibhavhrt
Copy link
Contributor

@vaibhavhrt vaibhavhrt commented May 25, 2019

@codecov
Copy link

codecov bot commented May 25, 2019

Codecov Report

Merging #26518 into master will decrease coverage by <.01%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master   #26518      +/-   ##
==========================================
- Coverage   91.76%   91.75%   -0.01%     
==========================================
  Files         174      174              
  Lines       50673    50673              
==========================================
- Hits        46498    46493       -5     
- Misses       4175     4180       +5
Flag Coverage Δ
#multiple 90.26% <100%> (ø) ⬆️
#single 41.7% <100%> (-0.08%) ⬇️
Impacted Files Coverage Δ
pandas/core/indexes/period.py 92.58% <100%> (ø) ⬆️
pandas/io/gbq.py 78.94% <0%> (-10.53%) ⬇️
pandas/core/frame.py 97% <0%> (-0.12%) ⬇️
pandas/util/testing.py 90.6% <0%> (-0.11%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 374478c...b311b66. Read the comment docs.

@codecov
Copy link

codecov bot commented May 25, 2019

Codecov Report

Merging #26518 into master will increase coverage by <.01%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master   #26518      +/-   ##
==========================================
+ Coverage   91.76%   91.76%   +<.01%     
==========================================
  Files         174      174              
  Lines       50673    50649      -24     
==========================================
- Hits        46498    46478      -20     
+ Misses       4175     4171       -4
Flag Coverage Δ
#multiple 90.3% <100%> (+0.04%) ⬆️
#single 41.67% <100%> (-0.12%) ⬇️
Impacted Files Coverage Δ
pandas/core/indexes/period.py 92.58% <100%> (ø) ⬆️
pandas/io/gbq.py 78.94% <0%> (-10.53%) ⬇️
pandas/io/excel/_base.py 91.81% <0%> (-0.33%) ⬇️
pandas/core/frame.py 97% <0%> (-0.12%) ⬇️
pandas/util/testing.py 90.6% <0%> (-0.11%) ⬇️
pandas/core/config_init.py 96.85% <0%> (-0.1%) ⬇️
pandas/core/sparse/scipy_sparse.py 100% <0%> (ø) ⬆️
pandas/core/series.py 93.61% <0%> (ø) ⬆️
pandas/core/sparse/frame.py 95.65% <0%> (+0.01%) ⬆️
pandas/core/sparse/series.py 93.24% <0%> (+0.06%) ⬆️
... and 5 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 374478c...3e1a81a. Read the comment docs.

@gfyoung gfyoung added Indexing Related to indexing on series/frames, not to indexes themselves Typing type annotations, mypy/pyright type checking labels May 25, 2019
Copy link
Member

@gfyoung gfyoung left a comment

Choose a reason for hiding this comment

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

Well, that was easy. Nice! 👍

@WillAyd : If you want to have a look before merging

@vaibhavhrt
Copy link
Contributor Author

@gfyoung yeah, I wanted to do it in #26404 but it got merged before I can make changes.

@@ -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

@WillAyd WillAyd added this to the 0.25.0 milestone May 25, 2019
Copy link
Member

@WillAyd WillAyd left a comment

Choose a reason for hiding this comment

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

@vaibhavhrt what is the purpose of this PR? I don't see any mypy failures in CI nor locally on master

@@ -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.

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

@@ -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.

@vaibhavhrt
Copy link
Contributor Author

@WillAyd mypy should give this error:

pandas\core\indexes\period.py:171: error: Incompatible types in assignment (expression has type "PeriodArray", base class "DatetimeIndexOpsMixin" defined the type as "None")

Can you double check.

@WillAyd
Copy link
Member

WillAyd commented May 27, 2019

I am not getting that error locally nor is it showing in the build. What version of mypy are you using?

@vaibhavhrt
Copy link
Contributor Author

vaibhavhrt commented May 27, 2019 via email

@WillAyd
Copy link
Member

WillAyd commented May 27, 2019 via email

@vaibhavhrt
Copy link
Contributor Author

vaibhavhrt commented May 27, 2019 via email

Copy link
Member

@WillAyd WillAyd left a comment

Choose a reason for hiding this comment

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

@vaibhavhrt all good was just a misunderstanding on my end

@@ -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.

Yea I think that should work here

@@ -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.

use 1d

@jreback jreback merged commit a91da0c into pandas-dev:master May 29, 2019
@jreback
Copy link
Contributor

jreback commented May 29, 2019

thanks @vaibhavhrt

@vaibhavhrt vaibhavhrt deleted the pandas.core.indexes.period branch May 29, 2019 16:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Indexing Related to indexing on series/frames, not to indexes themselves Typing type annotations, mypy/pyright type checking
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Fix type annotations in pandas.core.indexes.period
4 participants