diff --git a/pandas/core/indexes/base.py b/pandas/core/indexes/base.py index 9748342c86f31..68736935ed36d 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"] @@ -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): 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