11
11
ClassVar ,
12
12
Literal ,
13
13
NoReturn ,
14
+ Optional ,
15
+ Union ,
14
16
cast ,
15
17
final ,
16
18
overload ,
46
48
Axes ,
47
49
Axis ,
48
50
DropKeep ,
51
+ Dtype ,
49
52
DtypeObj ,
50
53
F ,
51
54
IgnoreRaise ,
155
158
ExtensionArray ,
156
159
TimedeltaArray ,
157
160
)
161
+ from pandas .core .arrays .floating import FloatingDtype
162
+ from pandas .core .arrays .integer import IntegerDtype
158
163
from pandas .core .arrays .string_ import (
159
164
StringArray ,
160
165
StringDtype ,
@@ -312,6 +317,20 @@ def _new_Index(cls, d):
312
317
return cls .__new__ (cls , ** d )
313
318
314
319
320
+ slice_type = Optional [
321
+ Union [
322
+ str ,
323
+ IntegerDtype ,
324
+ FloatingDtype ,
325
+ DatetimeTZDtype ,
326
+ CategoricalDtype ,
327
+ PeriodDtype ,
328
+ IntervalDtype ,
329
+ abc .Hashable ,
330
+ ]
331
+ ]
332
+
333
+
315
334
class Index (IndexOpsMixin , PandasObject ):
316
335
"""
317
336
Immutable sequence used for indexing and alignment.
@@ -1087,7 +1106,7 @@ def view(self, cls=None):
1087
1106
result ._id = self ._id
1088
1107
return result
1089
1108
1090
- def astype (self , dtype , copy : bool = True ):
1109
+ def astype (self , dtype : Dtype , copy : bool = True ):
1091
1110
"""
1092
1111
Create an Index with values cast to dtypes.
1093
1112
@@ -2957,7 +2976,7 @@ def _dti_setop_align_tzs(self, other: Index, setop: str_t) -> tuple[Index, Index
2957
2976
return self , other
2958
2977
2959
2978
@final
2960
- def union (self , other , sort = None ):
2979
+ def union (self , other , sort : bool | None = None ):
2961
2980
"""
2962
2981
Form the union of two Index objects.
2963
2982
@@ -3334,7 +3353,7 @@ def _intersection_via_get_indexer(
3334
3353
return result
3335
3354
3336
3355
@final
3337
- def difference (self , other , sort = None ):
3356
+ def difference (self , other , sort : bool | None = None ):
3338
3357
"""
3339
3358
Return a new Index with elements of index not in `other`.
3340
3359
@@ -3420,7 +3439,12 @@ def _wrap_difference_result(self, other, result):
3420
3439
# We will override for MultiIndex to handle empty results
3421
3440
return self ._wrap_setop_result (other , result )
3422
3441
3423
- def symmetric_difference (self , other , result_name = None , sort = None ):
3442
+ def symmetric_difference (
3443
+ self ,
3444
+ other ,
3445
+ result_name : abc .Hashable | None = None ,
3446
+ sort : bool | None = None ,
3447
+ ):
3424
3448
"""
3425
3449
Compute the symmetric difference of two Index objects.
3426
3450
@@ -6389,7 +6413,7 @@ def _transform_index(self, func, *, level=None) -> Index:
6389
6413
items = [func (x ) for x in self ]
6390
6414
return Index (items , name = self .name , tupleize_cols = False )
6391
6415
6392
- def isin (self , values , level = None ) -> npt .NDArray [np .bool_ ]:
6416
+ def isin (self , values , level : np . str_ | int | None = None ) -> npt .NDArray [np .bool_ ]:
6393
6417
"""
6394
6418
Return a boolean array where the index values are in `values`.
6395
6419
@@ -6687,7 +6711,12 @@ def get_slice_bound(self, label, side: Literal["left", "right"]) -> int:
6687
6711
else :
6688
6712
return slc
6689
6713
6690
- def slice_locs (self , start = None , end = None , step = None ) -> tuple [int , int ]:
6714
+ def slice_locs (
6715
+ self ,
6716
+ start : slice_type = None ,
6717
+ end : slice_type = None ,
6718
+ step : int | None = None ,
6719
+ ) -> tuple [int , int ]:
6691
6720
"""
6692
6721
Compute slice locations for input labels.
6693
6722
@@ -6781,7 +6810,7 @@ def slice_locs(self, start=None, end=None, step=None) -> tuple[int, int]:
6781
6810
6782
6811
return start_slice , end_slice
6783
6812
6784
- def delete (self , loc ) -> Self :
6813
+ def delete (self , loc : int | list [ int ] | np . ndarray ) -> Self :
6785
6814
"""
6786
6815
Make new Index with passed location(-s) deleted.
6787
6816
@@ -7227,7 +7256,9 @@ def _maybe_disable_logical_methods(self, opname: str_t) -> None:
7227
7256
raise TypeError (f"cannot perform { opname } with { type (self ).__name__ } " )
7228
7257
7229
7258
@Appender (IndexOpsMixin .argmin .__doc__ )
7230
- def argmin (self , axis = None , skipna : bool = True , * args , ** kwargs ) -> int :
7259
+ def argmin (
7260
+ self , axis : int | None = None , skipna : bool = True , * args , ** kwargs
7261
+ ) -> int :
7231
7262
nv .validate_argmin (args , kwargs )
7232
7263
nv .validate_minmax_axis (axis )
7233
7264
@@ -7240,7 +7271,9 @@ def argmin(self, axis=None, skipna: bool = True, *args, **kwargs) -> int:
7240
7271
return super ().argmin (skipna = skipna )
7241
7272
7242
7273
@Appender (IndexOpsMixin .argmax .__doc__ )
7243
- def argmax (self , axis = None , skipna : bool = True , * args , ** kwargs ) -> int :
7274
+ def argmax (
7275
+ self , axis : int | None = None , skipna : bool = True , * args , ** kwargs
7276
+ ) -> int :
7244
7277
nv .validate_argmax (args , kwargs )
7245
7278
nv .validate_minmax_axis (axis )
7246
7279
@@ -7251,7 +7284,7 @@ def argmax(self, axis=None, skipna: bool = True, *args, **kwargs) -> int:
7251
7284
raise ValueError ("Encountered all NA values" )
7252
7285
return super ().argmax (skipna = skipna )
7253
7286
7254
- def min (self , axis = None , skipna : bool = True , * args , ** kwargs ):
7287
+ def min (self , axis : int | None = None , skipna : bool = True , * args , ** kwargs ):
7255
7288
"""
7256
7289
Return the minimum value of the Index.
7257
7290
@@ -7314,7 +7347,7 @@ def min(self, axis=None, skipna: bool = True, *args, **kwargs):
7314
7347
7315
7348
return nanops .nanmin (self ._values , skipna = skipna )
7316
7349
7317
- def max (self , axis = None , skipna : bool = True , * args , ** kwargs ):
7350
+ def max (self , axis : int | None = None , skipna : bool = True , * args , ** kwargs ):
7318
7351
"""
7319
7352
Return the maximum value of the Index.
7320
7353
0 commit comments