-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
Remove pandas.core.index.datetimelike from MyPy Blacklist #26280
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
Changes from 7 commits
a3a1605
9c60e73
717bb83
4b3af23
29dbd92
213af4a
a5f7d7b
b7f5a9c
2bd7542
d9ab7b0
dea0cb1
b061ac1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
|
@@ -2,6 +2,7 @@ | |||
Base and utility classes for tseries type pandas objects. | ||||
""" | ||||
import operator | ||||
from typing import Set | ||||
import warnings | ||||
|
||||
import numpy as np | ||||
|
@@ -17,6 +18,7 @@ | |||
is_period_dtype, is_scalar) | ||||
from pandas.core.dtypes.generic import ABCIndex, ABCIndexClass, ABCSeries | ||||
|
||||
from pandas._typing import DatetimeLikeArray | ||||
from pandas.core import algorithms, ops | ||||
from pandas.core.accessor import PandasDelegate | ||||
from pandas.core.arrays import ExtensionOpsMixin | ||||
|
@@ -57,19 +59,22 @@ class DatetimeIndexOpsMixin(ExtensionOpsMixin): | |||
""" | ||||
common ops mixin to support a unified interface datetimelike Index | ||||
""" | ||||
_data = None | ||||
_data = None # type: DatetimeLikeArray | ||||
|
||||
# DatetimeLikeArrayMixin assumes subclasses are mutable, so these are | ||||
# properties there. They can be made into cache_readonly for Index | ||||
# subclasses bc they are immutable | ||||
inferred_freq = cache_readonly(DatetimeLikeArrayMixin.inferred_freq.fget) | ||||
_isnan = cache_readonly(DatetimeLikeArrayMixin._isnan.fget) | ||||
hasnans = cache_readonly(DatetimeLikeArrayMixin._hasnans.fget) | ||||
inferred_freq = cache_readonly( | ||||
DatetimeLikeArrayMixin.inferred_freq.fget) # type: ignore | ||||
_isnan = cache_readonly(DatetimeLikeArrayMixin._isnan.fget) # type: ignore | ||||
hasnans = cache_readonly( | ||||
DatetimeLikeArrayMixin._hasnans.fget) # type: ignore | ||||
_hasnans = hasnans # for index / array -agnostic code | ||||
_resolution = cache_readonly(DatetimeLikeArrayMixin._resolution.fget) | ||||
resolution = cache_readonly(DatetimeLikeArrayMixin.resolution.fget) | ||||
_resolution = cache_readonly( | ||||
DatetimeLikeArrayMixin._resolution.fget) # type: ignore | ||||
resolution = cache_readonly( | ||||
DatetimeLikeArrayMixin.resolution.fget) # type: ignore | ||||
|
||||
_box_values = ea_passthrough(DatetimeLikeArrayMixin._box_values) | ||||
_maybe_mask_results = ea_passthrough( | ||||
DatetimeLikeArrayMixin._maybe_mask_results) | ||||
__iter__ = ea_passthrough(DatetimeLikeArrayMixin.__iter__) | ||||
|
@@ -130,11 +135,11 @@ def _ndarray_values(self): | |||
# Abstract data attributes | ||||
|
||||
@property | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why this change? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. mypy has the following error for the annotated value function:
I add annotation pandas/pandas/core/indexes/datetimes.py Line 327 in 8154efb
I guess that mypy mixed up the instance attribute There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. cc @WillAyd There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry missed this ping. This could be a similar conversation to https://github.com/pandas-dev/pandas/pull/26518/files#r287573810 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think a better solution is to provide the appropriate type to cc @jbrockmendel in case he has other insights on the types here |
||||
def values(self) -> np.ndarray: | ||||
def values(self): | ||||
# Note: PeriodArray overrides this to return an ndarray of objects. | ||||
return self._data._data | ||||
|
||||
@property | ||||
@property # type: ignore # https://github.com/python/mypy/issues/1362 | ||||
@Appender(DatetimeLikeArrayMixin.asi8.__doc__) | ||||
def asi8(self): | ||||
return self._data.asi8 | ||||
|
@@ -761,9 +766,9 @@ class DatetimelikeDelegateMixin(PandasDelegate): | |||
boxed in an index, after being returned from the array | ||||
""" | ||||
# raw_methods : dispatch methods that shouldn't be boxed in an Index | ||||
_raw_methods = set() | ||||
_raw_methods = set() # type: Set[str] | ||||
# raw_properties : dispatch properties that shouldn't be boxed in an Index | ||||
_raw_properties = set() | ||||
_raw_properties = set() # type: Set[str] | ||||
name = None | ||||
_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.
don’t try to import these use a quoted version
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.
The following is the import error in the failed tests:
ImportError: cannot import name '_INT64_DTYPE'
The name of the module _typing.py is started with underscore. In PEP 8 (https://www.python.org/dev/peps/pep-0008/#descriptive-naming-styles ), it states
Should we remove underscore from the name _typing? Or something else?
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.
you can’t import these names as they would cause circular imports
and don’t need to just use ‘DatetimeArray’ and such
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.
_INT64_DTYPE
is just an alias, i.e.,_INT64_DTYPE = np.dtype(np.int64)
. The import of numpy and the definition of_INT64_DTYPE
are in the same filepandas/core/dtype/common.py
.I did a little experiment. Open a file called 'typing.py' (without underscore prefix) in the same directory as '_typing.py'. One can import
DatetimeArray
intyping.py
.Importing
PeriodArray
andTImedeltaArray
also run into the sameImportError
. Without them, one cannot define the mypy objectTypeVar
.DatetimeLikeArray = TypeVar('DatetimeLikeArray', DatetimeArray, PeriodArray, TimedeltaArray)
.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 Would you tell me your opinion? Should we change the filename of _typing.py?