Skip to content

Fix type annotations in pandas.core.indexes.datetimes #26404

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

Merged
merged 15 commits into from
May 24, 2019

Conversation

vaibhavhrt
Copy link
Contributor

@vaibhavhrt vaibhavhrt commented May 15, 2019

pandas/core/indexes/timedeltas.py taken care of as well since the errors were the same.

@vaibhavhrt
Copy link
Contributor Author

vaibhavhrt commented May 15, 2019

Errors that still remain are:

pandas\core\indexes\datetimes.py:90: error: Definition of "_data" in base class "DatetimeIndexOpsMixin" is incompatible with definition in base class "Index"
pandas\core\indexes\datetimes.py:90: error: Definition of "_data" in base class "DatetimeIndexOpsMixin" is incompatible with definition in base class "DatetimelikeDelegateMixin"
pandas\core\indexes\datetimes.py:90: error: Definition of "map" in base class "DatetimeIndexOpsMixin" is incompatible with definition in base class "Index"
pandas\core\indexes\datetimes.py:90: error: Definition of "_format_with_header" in base class "DatetimeIndexOpsMixin" is incompatible with definition in base class "Index"
pandas\core\indexes\datetimes.py:90: error: Definition of "isin" in base class "DatetimeIndexOpsMixin" is incompatible with definition in base class "Index"

Needs some investigation to decide a single type to use consistently for these attributes across all class.

@codecov
Copy link

codecov bot commented May 15, 2019

Codecov Report

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

Impacted file tree graph

@@            Coverage Diff             @@
##           master   #26404      +/-   ##
==========================================
- Coverage   91.69%   91.68%   -0.01%     
==========================================
  Files         174      174              
  Lines       50743    50744       +1     
==========================================
- Hits        46527    46525       -2     
- Misses       4216     4219       +3
Flag Coverage Δ
#multiple 90.19% <100%> (ø) ⬆️
#single 41.19% <100%> (-0.13%) ⬇️
Impacted Files Coverage Δ
pandas/core/indexes/datetimes.py 96.86% <100%> (ø) ⬆️
pandas/io/gbq.py 78.94% <0%> (-10.53%) ⬇️
pandas/core/frame.py 97.02% <0%> (-0.12%) ⬇️
pandas/util/testing.py 90.7% <0%> (+0.1%) ⬆️

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 3b24fb6...ca7e8eb. Read the comment docs.

@codecov
Copy link

codecov bot commented May 15, 2019

Codecov Report

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

Impacted file tree graph

@@            Coverage Diff             @@
##           master   #26404      +/-   ##
==========================================
- Coverage   91.74%   91.74%   -0.01%     
==========================================
  Files         174      174              
  Lines       50763    50764       +1     
==========================================
- Hits        46575    46573       -2     
- Misses       4188     4191       +3
Flag Coverage Δ
#multiple 90.25% <100%> (ø) ⬆️
#single 41.72% <83.33%> (-0.07%) ⬇️
Impacted Files Coverage Δ
pandas/core/indexes/datetimes.py 96.86% <100%> (ø) ⬆️
pandas/core/indexes/datetimelike.py 98.13% <100%> (ø) ⬆️
pandas/io/gbq.py 78.94% <0%> (-10.53%) ⬇️
pandas/core/frame.py 97.02% <0%> (-0.12%) ⬇️
pandas/util/testing.py 90.7% <0%> (+0.1%) ⬆️

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 44d5498...c4a17b5. Read the comment docs.

@WillAyd WillAyd added the Typing type annotations, mypy/pyright type checking label May 15, 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.

Looks like an isort failure in CI

@vaibhavhrt
Copy link
Contributor Author

@WillAyd some suggestion on what to do with these errors:

pandas\core\indexes\datetimes.py:89: error: Definition of "_data" in base class "DatetimeIndexOpsMixin" is incompatible with definition in base class "Index"
pandas\core\indexes\datetimes.py:89: error: Definition of "_data" in base class "DatetimeIndexOpsMixin" is incompatible with definition in base class "DatetimelikeDelegateMixin"
pandas\core\indexes\datetimes.py:89: error: Definition of "map" in base class "DatetimeIndexOpsMixin" is incompatible with definition in base class "Index"
pandas\core\indexes\datetimes.py:89: error: Definition of "_format_with_header" in base class "DatetimeIndexOpsMixin" is incompatible with definition in base class "Index"
pandas\core\indexes\datetimes.py:89: error: Definition of "isin" in base class "DatetimeIndexOpsMixin" is incompatible with definition in base class "Index"

List of attributes with conflicting types:

  1. _data

    Class Type Initial Value
    DatetimeIndexOpsMixin DatetimeLikeArrayMixin None
    DatetimelikeDelegateMixin None (using reveal_type) None
    Index None (using reveal_type) None

    I don't think we should use DatetimeLikeArrayMixin in all three classes. Should I remove the type comment from class DatetimeIndexOpsMixin too?
    Making it Optional[DatetimeLikeArrayMixin] in class DatetimeIndexOpsMixin will not fix the error.

  2. map

    Class Defintion
    DatetimeIndexOpsMixin def map(self, f):
    Index def map(self, mapper, na_action=None):
  3. _format_with_header

    Class Defintion
    DatetimeIndexOpsMixin def _format_with_header(self, header, **kwargs):
    Index def _format_with_header(self, header, na_rep='NaN', **kwargs):
  4. isin

    Class Defintion
    DatetimeIndexOpsMixin def isin(self, values):
    Index def isin(self, values, level=None):

I don't see any easy way of fixing the methods which have different parameters. Maybe we should just ignore these errors too.

@WillAyd
Copy link
Member

WillAyd commented May 18, 2019

Haven’t been able to deeply review but you can try aligning the signatures for the methods - seems like the difference is only optional keywords anyway

@vaibhavhrt
Copy link
Contributor Author

@WillAyd I can fix the last two but what about def map(self, f) and def map(self, mapper, na_action=None). Is f and mapper the same thing?

@WillAyd
Copy link
Member

WillAyd commented May 19, 2019

I would think they are the same

@jreback jreback added this to the 0.25.0 milestone May 19, 2019
@jreback
Copy link
Contributor

jreback commented May 19, 2019

this is ok, @vaibhavhrt you have some checks issue, can you fix up and ping on green

Copy link
Contributor Author

@vaibhavhrt vaibhavhrt left a comment

Choose a reason for hiding this comment

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

Make tests pass!

@vaibhavhrt
Copy link
Contributor Author

@WillAyd @jreback I have made all changes and tests are passing now. Please review.

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.

lgtm @jreback

@vaibhavhrt
Copy link
Contributor Author

@jreback please review and merge.

@plammens
Copy link
Contributor

I don't think we should use DatetimeLikeArrayMixin in all three classes. Should I remove the type comment from class DatetimeIndexOpsMixin too?
Making it Optional[DatetimeLikeArrayMixin] in class DatetimeIndexOpsMixin will not fix the error.

I think DatetimeLikeArrayMixin for both Datetime* classes and np.ndarray for Index is also an option–it works, and it is the option that makes most sense to me. (Also because there is a comment that says

# Index._data must always be an ndarray.
).

@vaibhavhrt
Copy link
Contributor Author

@plammens there are a million different classes that inherits from the Index class and all those child classes have some different type for data.

@jreback jreback merged commit 38dd858 into pandas-dev:master May 24, 2019
@jreback
Copy link
Contributor

jreback commented May 24, 2019

thanks @vaibhavhrt

@pandas-dev pandas-dev deleted a comment from jreback May 24, 2019
@vaibhavhrt vaibhavhrt deleted the pandas.core.indexes.datetimes branch May 24, 2019 23:43
another-green pushed a commit to another-green/pandas that referenced this pull request May 29, 2019
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.

Fix type annotations for pandas.core.indexes.datetimes
4 participants