From 8f671368470adc11d844aaf48b1b42c79d7c6f03 Mon Sep 17 00:00:00 2001 From: jbrockmendel Date: Tue, 12 Nov 2019 13:21:24 -0800 Subject: [PATCH 1/2] ANN: annotate _data --- pandas/core/indexes/base.py | 2 +- pandas/core/indexes/datetimelike.py | 6 +++--- pandas/core/indexes/period.py | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/pandas/core/indexes/base.py b/pandas/core/indexes/base.py index ee124ba3851b1..a2d88df2b2c1b 100644 --- a/pandas/core/indexes/base.py +++ b/pandas/core/indexes/base.py @@ -230,7 +230,7 @@ def _outer_indexer(self, left, right): return libjoin.outer_join_indexer(left, right) _typ = "index" - _data = None + _data: Union[ExtensionArray, np.ndarray] _id = None name = None _comparables = ["name"] diff --git a/pandas/core/indexes/datetimelike.py b/pandas/core/indexes/datetimelike.py index bf89bbbdf2b79..f694b85f1ca5d 100644 --- a/pandas/core/indexes/datetimelike.py +++ b/pandas/core/indexes/datetimelike.py @@ -27,7 +27,7 @@ from pandas.core import algorithms, ops from pandas.core.accessor import PandasDelegate -from pandas.core.arrays import ExtensionOpsMixin +from pandas.core.arrays import ExtensionArray, ExtensionOpsMixin from pandas.core.arrays.datetimelike import ( DatetimeLikeArrayMixin, _ensure_datetimelike_to_i8, @@ -78,7 +78,7 @@ class DatetimeIndexOpsMixin(ExtensionOpsMixin): common ops mixin to support a unified interface datetimelike Index """ - _data = None + _data: ExtensionArray # DatetimeLikeArrayMixin assumes subclasses are mutable, so these are # properties there. They can be made into cache_readonly for Index @@ -836,7 +836,7 @@ class DatetimelikeDelegateMixin(PandasDelegate): # raw_properties : dispatch properties that shouldn't be boxed in an Index _raw_properties = set() # type: Set[str] name = None - _data = None + _data: ExtensionArray @property def _delegate_class(self): diff --git a/pandas/core/indexes/period.py b/pandas/core/indexes/period.py index 3bcb9ba345713..2b70049fd14af 100644 --- a/pandas/core/indexes/period.py +++ b/pandas/core/indexes/period.py @@ -174,7 +174,7 @@ class PeriodIndex(DatetimeIndexOpsMixin, Int64Index, PeriodDelegateMixin): _is_numeric_dtype = False _infer_as_myclass = True - _data = None + _data: PeriodArray _engine_type = libindex.PeriodEngine _supports_partial_string_indexing = True From 50fc54f0b667ae1361394f11433153091cbad37a Mon Sep 17 00:00:00 2001 From: jbrockmendel Date: Wed, 13 Nov 2019 07:26:05 -0800 Subject: [PATCH 2/2] revert assertion --- pandas/core/indexes/base.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/pandas/core/indexes/base.py b/pandas/core/indexes/base.py index fb54ea1f1a677..68736935ed36d 100644 --- a/pandas/core/indexes/base.py +++ b/pandas/core/indexes/base.py @@ -653,8 +653,6 @@ def __len__(self) -> int: """ Return the length of the Index. """ - # Assertion needed for mypy, see GH#29475 - assert self._data is not None return len(self._data) def __array__(self, dtype=None):