Skip to content

Commit 4cb9044

Browse files
authored
TYP: Annotate (#31397)
1 parent ba9f5af commit 4cb9044

File tree

7 files changed

+19
-14
lines changed

7 files changed

+19
-14
lines changed

pandas/core/indexes/base.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
from pandas._libs.tslibs import OutOfBoundsDatetime, Timestamp
1313
from pandas._libs.tslibs.period import IncompatibleFrequency
1414
from pandas._libs.tslibs.timezones import tz_compare
15+
from pandas._typing import Label
1516
from pandas.compat import set_function_name
1617
from pandas.compat.numpy import function as nv
1718
from pandas.util._decorators import Appender, Substitution, cache_readonly
@@ -243,7 +244,7 @@ def _outer_indexer(self, left, right):
243244
_typ = "index"
244245
_data: Union[ExtensionArray, np.ndarray]
245246
_id = None
246-
_name: Optional[Hashable] = None
247+
_name: Label = None
247248
# MultiIndex.levels previously allowed setting the index name. We
248249
# don't allow this anymore, and raise if it happens rather than
249250
# failing silently.
@@ -4126,7 +4127,7 @@ def _assert_can_do_op(self, value):
41264127
raise TypeError(f"'value' must be a scalar, passed: {type(value).__name__}")
41274128

41284129
@property
4129-
def _has_complex_internals(self):
4130+
def _has_complex_internals(self) -> bool:
41304131
"""
41314132
Indicates if an index is not directly backed by a numpy array
41324133
"""

pandas/core/indexes/category.py

+5-4
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,7 @@ class CategoricalIndex(ExtensionIndex, accessor.PandasDelegate):
172172

173173
codes: np.ndarray
174174
categories: Index
175+
_data: Categorical
175176

176177
@property
177178
def _engine_type(self):
@@ -312,7 +313,7 @@ def _is_dtype_compat(self, other) -> bool:
312313

313314
return other
314315

315-
def equals(self, other):
316+
def equals(self, other) -> bool:
316317
"""
317318
Determine if two CategoricalIndex objects contain the same elements.
318319
@@ -381,7 +382,7 @@ def values(self):
381382
return self._data
382383

383384
@property
384-
def _has_complex_internals(self):
385+
def _has_complex_internals(self) -> bool:
385386
# used to avoid libreduction code paths, which raise or require conversion
386387
return True
387388

@@ -851,12 +852,12 @@ def _concat_same_dtype(self, to_concat, name):
851852
result.name = name
852853
return result
853854

854-
def _delegate_property_get(self, name, *args, **kwargs):
855+
def _delegate_property_get(self, name: str, *args, **kwargs):
855856
""" method delegation to the ._values """
856857
prop = getattr(self._values, name)
857858
return prop # no wrapping for now
858859

859-
def _delegate_method(self, name, *args, **kwargs):
860+
def _delegate_method(self, name: str, *args, **kwargs):
860861
""" method delegation to the ._values """
861862
method = getattr(self._values, name)
862863
if "inplace" in kwargs:

pandas/core/indexes/datetimelike.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
Base and utility classes for tseries type pandas objects.
33
"""
44
import operator
5-
from typing import Any, List, Optional, Set
5+
from typing import Any, List, Optional, Set, Union
66

77
import numpy as np
88

@@ -31,7 +31,7 @@
3131

3232
from pandas.core import algorithms
3333
from pandas.core.accessor import PandasDelegate
34-
from pandas.core.arrays import DatetimeArray, ExtensionArray, TimedeltaArray
34+
from pandas.core.arrays import DatetimeArray, PeriodArray, TimedeltaArray
3535
from pandas.core.arrays.datetimelike import DatetimeLikeArrayMixin
3636
from pandas.core.base import _shared_docs
3737
import pandas.core.indexes.base as ibase
@@ -90,7 +90,7 @@ class DatetimeIndexOpsMixin(ExtensionIndex):
9090
Common ops mixin to support a unified interface datetimelike Index.
9191
"""
9292

93-
_data: ExtensionArray
93+
_data: Union[DatetimeArray, TimedeltaArray, PeriodArray]
9494
freq: Optional[DateOffset]
9595
freqstr: Optional[str]
9696
_resolution: int
@@ -468,7 +468,7 @@ def where(self, cond, other=None):
468468
result = np.where(cond, values, other).astype("i8")
469469
return self._shallow_copy(result)
470470

471-
def _summary(self, name=None):
471+
def _summary(self, name=None) -> str:
472472
"""
473473
Return a summarized representation.
474474
@@ -955,15 +955,15 @@ class DatetimelikeDelegateMixin(PandasDelegate):
955955
_raw_methods: Set[str] = set()
956956
# raw_properties : dispatch properties that shouldn't be boxed in an Index
957957
_raw_properties: Set[str] = set()
958-
_data: ExtensionArray
958+
_data: Union[DatetimeArray, TimedeltaArray, PeriodArray]
959959

960960
def _delegate_property_get(self, name, *args, **kwargs):
961961
result = getattr(self._data, name)
962962
if name not in self._raw_properties:
963963
result = Index(result, name=self.name)
964964
return result
965965

966-
def _delegate_property_set(self, name, value, *args, **kwargs):
966+
def _delegate_property_set(self, name: str, value, *args, **kwargs):
967967
setattr(self._data, name, value)
968968

969969
def _delegate_method(self, name, *args, **kwargs):

pandas/core/indexes/datetimes.py

+1
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,7 @@ class DatetimeIndex(DatetimeTimedeltaMixin):
198198
_is_numeric_dtype = False
199199
_infer_as_myclass = True
200200

201+
_data: DatetimeArray
201202
tz: Optional[tzinfo]
202203

203204
# --------------------------------------------------------------------

pandas/core/indexes/interval.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -405,7 +405,7 @@ def values(self):
405405
return self._data
406406

407407
@property
408-
def _has_complex_internals(self):
408+
def _has_complex_internals(self) -> bool:
409409
# used to avoid libreduction code paths, which raise or require conversion
410410
return True
411411

pandas/core/indexes/multi.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1347,7 +1347,7 @@ def values(self):
13471347
return self._tuples
13481348

13491349
@property
1350-
def _has_complex_internals(self):
1350+
def _has_complex_internals(self) -> bool:
13511351
# used to avoid libreduction code paths, which raise or require conversion
13521352
return True
13531353

pandas/core/indexes/timedeltas.py

+2
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,8 @@ class TimedeltaIndex(DatetimeTimedeltaMixin, dtl.TimelikeOps):
130130
_is_numeric_dtype = True
131131
_infer_as_myclass = True
132132

133+
_data: TimedeltaArray
134+
133135
# -------------------------------------------------------------------
134136
# Constructors
135137

0 commit comments

Comments
 (0)