-
-
Notifications
You must be signed in to change notification settings - Fork 18.2k
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
Fix type annotations in pandas.core.indexes.period #26518
Conversation
Codecov Report
@@ 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
Continue to review full report at Codecov.
|
Codecov Report
@@ 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
Continue to review full report at Codecov.
|
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.
Well, that was easy. Nice! 👍
@WillAyd : If you want to have a look before merging
@@ -168,7 +168,7 @@ class PeriodIndex(DatetimeIndexOpsMixin, Int64Index, PeriodDelegateMixin): | |||
_is_numeric_dtype = False | |||
_infer_as_myclass = True | |||
|
|||
_data = None # type: PeriodArray | |||
_data = None |
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 what is this getting inferred as now?
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.
@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.
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.
We already have that in the typing module - did that not work?
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.
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.
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.
Yea I think that should work here
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.
@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 |
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.
We already have that in the typing module - did that not work?
pandas/core/indexes/period.py
Outdated
@@ -80,7 +80,7 @@ class PeriodIndex(DatetimeIndexOpsMixin, Int64Index, PeriodDelegateMixin): | |||
|
|||
Parameters | |||
---------- | |||
data : array-like (1-dimensional), optional | |||
data : array-like (1-dimensional) - PeriodArray, optional |
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.
this is not very clear, can you enumerate a bit
1d int np.ndarray or PeriodArray, optional
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.
data : array-like (1-dimensional integer np.ndarray or PeriodArray), optional
, looks good?
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.
use 1d
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.
Okay, I will get it done after a few hours
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.
@jreback I have fixed it, sorry for the delay.
@WillAyd mypy should give this error:
Can you double check. |
I am not getting that error locally nor is it showing in the build. What version of mypy are you using? |
Hmm, let me double check.
…On Mon, 27 May 2019, 5:31 am William Ayd, ***@***.***> wrote:
I am not getting that error locally nor is it showing in the build. What
version of mypy are you using?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#26518?email_source=notifications&email_token=AFMJMLFFPBOUUX7NRDK4PVTPXMQFTA5CNFSM4HPTL2JKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGODWIP6BI#issuecomment-496041733>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AFMJMLESB65Q2CBRERGMP53PXMQFTANCNFSM4HPTL2JA>
.
|
Might be a misunderstanding on my end I didn’t modify mypy.ini before running. Thought this was a continuation of a prior PR but if not that’s probably it. Can check later
…Sent from my iPhone
On May 26, 2019, at 9:34 AM, Vaibhav Vishal ***@***.***> wrote:
@vaibhavhrt commented on this pull request.
In pandas/core/indexes/period.py:
> @@ -80,7 +80,7 @@ class PeriodIndex(DatetimeIndexOpsMixin, Int64Index, PeriodDelegateMixin):
Parameters
----------
- data : array-like (1-dimensional), optional
+ data : array-like (1-dimensional) - PeriodArray, optional
data : array-like (1-dimensional integer np.ndarray or PeriodArray), optional, looks good?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub, or mute the thread.
|
`pandas.core.indexes.period` needs to be removed from mypy.ini. I wanted to
fix this error in a previous PR because `pandas.core.indexes.period` had a
lot of other errors too relating to incompatible types which got
automatically solved while trying to fix types in some other file. Just
this one remained so a new PR was not absolutely necessary, but since that
PR(#26404 I think) got merged before I could fix
`pandas.core.indexes.period` too, so a new PR, sorry for the confusion.
On Mon, May 27, 2019 at 6:35 AM William Ayd <[email protected]>
wrote:
… Might be a misunderstanding on my end I didn’t modify mypy.ini before
running. Thought this was a continuation of a prior PR but if not that’s
probably it. Can check later
Sent from my iPhone
> On May 26, 2019, at 9:34 AM, Vaibhav Vishal ***@***.***>
wrote:
>
> @vaibhavhrt commented on this pull request.
>
> In pandas/core/indexes/period.py:
>
> > @@ -80,7 +80,7 @@ class PeriodIndex(DatetimeIndexOpsMixin, Int64Index,
PeriodDelegateMixin):
>
> Parameters
> ----------
> - data : array-like (1-dimensional), optional
> + data : array-like (1-dimensional) - PeriodArray, optional
> data : array-like (1-dimensional integer np.ndarray or PeriodArray),
optional, looks good?
>
> —
> You are receiving this because you were mentioned.
> Reply to this email directly, view it on GitHub, or mute the thread.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#26518?email_source=notifications&email_token=AFMJMLCZ6RZW7XVCR3NESCLPXMXWLA5CNFSM4HPTL2JKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGODWIRHXA#issuecomment-496047068>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AFMJMLAWOYH5N2IC5JMTNZTPXMXWLANCNFSM4HPTL2JA>
.
|
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.
@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 |
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.
Yea I think that should work here
pandas/core/indexes/period.py
Outdated
@@ -80,7 +80,7 @@ class PeriodIndex(DatetimeIndexOpsMixin, Int64Index, PeriodDelegateMixin): | |||
|
|||
Parameters | |||
---------- | |||
data : array-like (1-dimensional), optional | |||
data : array-like (1-dimensional) - PeriodArray, optional |
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.
use 1d
thanks @vaibhavhrt |
git diff upstream/master -u -- "*.py" | flake8 --diff