diff --git a/pandas/core/indexes/base.py b/pandas/core/indexes/base.py index 5274213f114e3..6f3c1561ff5db 100644 --- a/pandas/core/indexes/base.py +++ b/pandas/core/indexes/base.py @@ -12,6 +12,7 @@ from pandas._libs.tslibs import OutOfBoundsDatetime, Timestamp from pandas._libs.tslibs.period import IncompatibleFrequency from pandas._libs.tslibs.timezones import tz_compare +from pandas._typing import Label from pandas.compat import set_function_name from pandas.compat.numpy import function as nv from pandas.util._decorators import Appender, Substitution, cache_readonly @@ -243,7 +244,7 @@ def _outer_indexer(self, left, right): _typ = "index" _data: Union[ExtensionArray, np.ndarray] _id = None - _name: Optional[Hashable] = None + _name: Label = None # MultiIndex.levels previously allowed setting the index name. We # don't allow this anymore, and raise if it happens rather than # failing silently. @@ -4126,7 +4127,7 @@ def _assert_can_do_op(self, value): raise TypeError(f"'value' must be a scalar, passed: {type(value).__name__}") @property - def _has_complex_internals(self): + def _has_complex_internals(self) -> bool: """ Indicates if an index is not directly backed by a numpy array """ diff --git a/pandas/core/indexes/category.py b/pandas/core/indexes/category.py index 1a53596fb5967..235d1856a2d0b 100644 --- a/pandas/core/indexes/category.py +++ b/pandas/core/indexes/category.py @@ -172,6 +172,7 @@ class CategoricalIndex(ExtensionIndex, accessor.PandasDelegate): codes: np.ndarray categories: Index + _data: Categorical @property def _engine_type(self): @@ -312,7 +313,7 @@ def _is_dtype_compat(self, other) -> bool: return other - def equals(self, other): + def equals(self, other) -> bool: """ Determine if two CategoricalIndex objects contain the same elements. @@ -381,7 +382,7 @@ def values(self): return self._data @property - def _has_complex_internals(self): + def _has_complex_internals(self) -> bool: # used to avoid libreduction code paths, which raise or require conversion return True @@ -851,12 +852,12 @@ def _concat_same_dtype(self, to_concat, name): result.name = name return result - def _delegate_property_get(self, name, *args, **kwargs): + def _delegate_property_get(self, name: str, *args, **kwargs): """ method delegation to the ._values """ prop = getattr(self._values, name) return prop # no wrapping for now - def _delegate_method(self, name, *args, **kwargs): + def _delegate_method(self, name: str, *args, **kwargs): """ method delegation to the ._values """ method = getattr(self._values, name) if "inplace" in kwargs: diff --git a/pandas/core/indexes/datetimelike.py b/pandas/core/indexes/datetimelike.py index b87dd0f02252f..0f385d9aba9c5 100644 --- a/pandas/core/indexes/datetimelike.py +++ b/pandas/core/indexes/datetimelike.py @@ -2,7 +2,7 @@ Base and utility classes for tseries type pandas objects. """ import operator -from typing import Any, List, Optional, Set +from typing import Any, List, Optional, Set, Union import numpy as np @@ -31,7 +31,7 @@ from pandas.core import algorithms from pandas.core.accessor import PandasDelegate -from pandas.core.arrays import DatetimeArray, ExtensionArray, TimedeltaArray +from pandas.core.arrays import DatetimeArray, PeriodArray, TimedeltaArray from pandas.core.arrays.datetimelike import DatetimeLikeArrayMixin from pandas.core.base import _shared_docs import pandas.core.indexes.base as ibase @@ -90,7 +90,7 @@ class DatetimeIndexOpsMixin(ExtensionIndex): Common ops mixin to support a unified interface datetimelike Index. """ - _data: ExtensionArray + _data: Union[DatetimeArray, TimedeltaArray, PeriodArray] freq: Optional[DateOffset] freqstr: Optional[str] _resolution: int @@ -468,7 +468,7 @@ def where(self, cond, other=None): result = np.where(cond, values, other).astype("i8") return self._shallow_copy(result) - def _summary(self, name=None): + def _summary(self, name=None) -> str: """ Return a summarized representation. @@ -955,7 +955,7 @@ class DatetimelikeDelegateMixin(PandasDelegate): _raw_methods: Set[str] = set() # raw_properties : dispatch properties that shouldn't be boxed in an Index _raw_properties: Set[str] = set() - _data: ExtensionArray + _data: Union[DatetimeArray, TimedeltaArray, PeriodArray] def _delegate_property_get(self, name, *args, **kwargs): result = getattr(self._data, name) @@ -963,7 +963,7 @@ def _delegate_property_get(self, name, *args, **kwargs): result = Index(result, name=self.name) return result - def _delegate_property_set(self, name, value, *args, **kwargs): + def _delegate_property_set(self, name: str, value, *args, **kwargs): setattr(self._data, name, value) def _delegate_method(self, name, *args, **kwargs): diff --git a/pandas/core/indexes/datetimes.py b/pandas/core/indexes/datetimes.py index 3afd1ff35806d..4e5e9fa0758c6 100644 --- a/pandas/core/indexes/datetimes.py +++ b/pandas/core/indexes/datetimes.py @@ -218,6 +218,7 @@ class DatetimeIndex(DatetimeTimedeltaMixin, DatetimeDelegateMixin): _is_numeric_dtype = False _infer_as_myclass = True + _data: DatetimeArray tz: Optional[tzinfo] # -------------------------------------------------------------------- diff --git a/pandas/core/indexes/interval.py b/pandas/core/indexes/interval.py index 26b64836172fd..b7edb1c3bcbca 100644 --- a/pandas/core/indexes/interval.py +++ b/pandas/core/indexes/interval.py @@ -405,7 +405,7 @@ def values(self): return self._data @property - def _has_complex_internals(self): + def _has_complex_internals(self) -> bool: # used to avoid libreduction code paths, which raise or require conversion return True diff --git a/pandas/core/indexes/multi.py b/pandas/core/indexes/multi.py index 5a9825d58b204..02db7be1ddf41 100644 --- a/pandas/core/indexes/multi.py +++ b/pandas/core/indexes/multi.py @@ -1347,7 +1347,7 @@ def values(self): return self._tuples @property - def _has_complex_internals(self): + def _has_complex_internals(self) -> bool: # used to avoid libreduction code paths, which raise or require conversion return True diff --git a/pandas/core/indexes/timedeltas.py b/pandas/core/indexes/timedeltas.py index 1257e410b4125..45afdaf33421d 100644 --- a/pandas/core/indexes/timedeltas.py +++ b/pandas/core/indexes/timedeltas.py @@ -135,6 +135,8 @@ class TimedeltaIndex( _is_numeric_dtype = True _infer_as_myclass = True + _data: TimedeltaArray + # ------------------------------------------------------------------- # Constructors