Skip to content
Prev Previous commit
Next Next commit
Add ignore comment
  • Loading branch information
makbigc committed May 30, 2019
commit 29dbd929942d28d952964118d069559dbcc0b4b2
16 changes: 10 additions & 6 deletions pandas/core/indexes/datetimelike.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,16 @@ class DatetimeIndexOpsMixin(ExtensionOpsMixin):
# 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

_maybe_mask_results = ea_passthrough(
DatetimeLikeArrayMixin._maybe_mask_results)
Expand Down Expand Up @@ -130,7 +134,7 @@ def _ndarray_values(self):
# Abstract data attributes

@property
Copy link
Contributor

Choose a reason for hiding this comment

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

why this change?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

mypy has the following error for the annotated value function:

pandas/core/indexes/datetimelike.py:139: error: "None" has no attribute "_data"

I add annotation # type: DatetimeArray to _data. But mypy still has the same error.

result._data = dtarr

I guess that mypy mixed up the instance attribute _data with the class attributes _data which is set None in the beginning of DatetimeIndexOpsMixin.

Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

The 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

Copy link
Member

Choose a reason for hiding this comment

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

I think a better solution is to provide the appropriate type to _data. Can you create a DatetimeLikeArray in pandas._typing which should be something like DatetimeLikeArray = TypeVar('DatetimeLikeArray', DatetimeArray, PeriodArray, TimedeltaArray) and assign that type to _data in the class? I think that should resolve.

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

Expand Down