45
45
Shape ,
46
46
T ,
47
47
final ,
48
+ npt ,
48
49
)
49
50
from pandas .compat .numpy import function as nv
50
51
from pandas .errors import (
@@ -306,8 +307,7 @@ class Index(IndexOpsMixin, PandasObject):
306
307
# given the dtypes of the passed arguments
307
308
308
309
@final
309
- def _left_indexer_unique (self : _IndexT , other : _IndexT ) -> np .ndarray :
310
- # -> np.ndarray[np.intp]
310
+ def _left_indexer_unique (self : _IndexT , other : _IndexT ) -> npt .NDArray [np .intp ]:
311
311
# Caller is responsible for ensuring other.dtype == self.dtype
312
312
sv = self ._get_join_target ()
313
313
ov = other ._get_join_target ()
@@ -316,7 +316,7 @@ def _left_indexer_unique(self: _IndexT, other: _IndexT) -> np.ndarray:
316
316
@final
317
317
def _left_indexer (
318
318
self : _IndexT , other : _IndexT
319
- ) -> tuple [ArrayLike , np .ndarray , np .ndarray ]:
319
+ ) -> tuple [ArrayLike , npt . NDArray [ np .intp ], npt . NDArray [ np .intp ] ]:
320
320
# Caller is responsible for ensuring other.dtype == self.dtype
321
321
sv = self ._get_join_target ()
322
322
ov = other ._get_join_target ()
@@ -327,7 +327,7 @@ def _left_indexer(
327
327
@final
328
328
def _inner_indexer (
329
329
self : _IndexT , other : _IndexT
330
- ) -> tuple [ArrayLike , np .ndarray , np .ndarray ]:
330
+ ) -> tuple [ArrayLike , npt . NDArray [ np .intp ], npt . NDArray [ np .intp ] ]:
331
331
# Caller is responsible for ensuring other.dtype == self.dtype
332
332
sv = self ._get_join_target ()
333
333
ov = other ._get_join_target ()
@@ -338,7 +338,7 @@ def _inner_indexer(
338
338
@final
339
339
def _outer_indexer (
340
340
self : _IndexT , other : _IndexT
341
- ) -> tuple [ArrayLike , np .ndarray , np .ndarray ]:
341
+ ) -> tuple [ArrayLike , npt . NDArray [ np .intp ], npt . NDArray [ np .intp ] ]:
342
342
# Caller is responsible for ensuring other.dtype == self.dtype
343
343
sv = self ._get_join_target ()
344
344
ov = other ._get_join_target ()
@@ -3460,8 +3460,7 @@ def get_indexer(
3460
3460
method : str_t | None = None ,
3461
3461
limit : int | None = None ,
3462
3462
tolerance = None ,
3463
- ) -> np .ndarray :
3464
- # returned ndarray is np.intp
3463
+ ) -> npt .NDArray [np .intp ]:
3465
3464
method = missing .clean_reindex_fill_method (method )
3466
3465
target = self ._maybe_cast_listlike_indexer (target )
3467
3466
@@ -3842,7 +3841,7 @@ def _validate_can_reindex(self, indexer: np.ndarray) -> None:
3842
3841
3843
3842
def reindex (
3844
3843
self , target , method = None , level = None , limit = None , tolerance = None
3845
- ) -> tuple [Index , np .ndarray | None ]:
3844
+ ) -> tuple [Index , npt . NDArray [ np .intp ] | None ]:
3846
3845
"""
3847
3846
Create index with target's values.
3848
3847
@@ -3918,7 +3917,7 @@ def _maybe_preserve_names(self, target: Index, preserve_names: bool):
3918
3917
@final
3919
3918
def _reindex_non_unique (
3920
3919
self , target : Index
3921
- ) -> tuple [Index , np .ndarray , np .ndarray | None ]:
3920
+ ) -> tuple [Index , npt . NDArray [ np .intp ], npt . NDArray [ np .intp ] | None ]:
3922
3921
"""
3923
3922
Create a new index with target's values (move/add/delete values as
3924
3923
necessary) use with non-unique Index and a possibly non-unique target.
@@ -4206,8 +4205,7 @@ def _join_multi(self, other: Index, how: str_t):
4206
4205
@final
4207
4206
def _join_non_unique (
4208
4207
self , other : Index , how : str_t = "left"
4209
- ) -> tuple [Index , np .ndarray , np .ndarray ]:
4210
- # returned ndarrays are np.intp
4208
+ ) -> tuple [Index , npt .NDArray [np .intp ], npt .NDArray [np .intp ]]:
4211
4209
from pandas .core .reshape .merge import get_join_indexers
4212
4210
4213
4211
# We only get here if dtypes match
@@ -4235,8 +4233,7 @@ def _join_non_unique(
4235
4233
@final
4236
4234
def _join_level (
4237
4235
self , other : Index , level , how : str_t = "left" , keep_order : bool = True
4238
- ) -> tuple [MultiIndex , np .ndarray | None , np .ndarray | None ]:
4239
- # Any returned ndarrays are np.intp
4236
+ ) -> tuple [MultiIndex , npt .NDArray [np .intp ] | None , npt .NDArray [np .intp ] | None ]:
4240
4237
"""
4241
4238
The join method *only* affects the level of the resulting
4242
4239
MultiIndex. Otherwise it just exactly aligns the Index data to the
@@ -4248,7 +4245,7 @@ def _join_level(
4248
4245
"""
4249
4246
from pandas .core .indexes .multi import MultiIndex
4250
4247
4251
- def _get_leaf_sorter (labels : list [np .ndarray ]) -> np .ndarray :
4248
+ def _get_leaf_sorter (labels : list [np .ndarray ]) -> npt . NDArray [ np .intp ] :
4252
4249
"""
4253
4250
Returns sorter for the inner most level while preserving the
4254
4251
order of higher levels.
@@ -5000,7 +4997,7 @@ def asof(self, label):
5000
4997
5001
4998
return self [loc ]
5002
4999
5003
- def asof_locs (self , where : Index , mask : np .ndarray ) -> np .ndarray :
5000
+ def asof_locs (self , where : Index , mask : np .ndarray ) -> npt . NDArray [ np .intp ] :
5004
5001
"""
5005
5002
Return the locations (indices) of labels in the index.
5006
5003
@@ -5191,7 +5188,7 @@ def shift(self, periods=1, freq=None):
5191
5188
f"TimedeltaIndex; Got type { type (self ).__name__ } "
5192
5189
)
5193
5190
5194
- def argsort (self , * args , ** kwargs ) -> np .ndarray :
5191
+ def argsort (self , * args , ** kwargs ) -> npt . NDArray [ np .intp ] :
5195
5192
"""
5196
5193
Return the integer indices that would sort the index.
5197
5194
@@ -5342,8 +5339,9 @@ def set_value(self, arr, key, value):
5342
5339
"""
5343
5340
5344
5341
@Appender (_index_shared_docs ["get_indexer_non_unique" ] % _index_doc_kwargs )
5345
- def get_indexer_non_unique (self , target ) -> tuple [np .ndarray , np .ndarray ]:
5346
- # both returned ndarrays are np.intp
5342
+ def get_indexer_non_unique (
5343
+ self , target
5344
+ ) -> tuple [npt .NDArray [np .intp ], npt .NDArray [np .intp ]]:
5347
5345
target = ensure_index (target )
5348
5346
target = self ._maybe_cast_listlike_indexer (target )
5349
5347
@@ -5373,7 +5371,7 @@ def get_indexer_non_unique(self, target) -> tuple[np.ndarray, np.ndarray]:
5373
5371
return ensure_platform_int (indexer ), ensure_platform_int (missing )
5374
5372
5375
5373
@final
5376
- def get_indexer_for (self , target ) -> np .ndarray :
5374
+ def get_indexer_for (self , target ) -> npt . NDArray [ np .intp ] :
5377
5375
"""
5378
5376
Guaranteed return of an indexer even when non-unique.
5379
5377
@@ -5393,28 +5391,25 @@ def get_indexer_for(self, target) -> np.ndarray:
5393
5391
@overload
5394
5392
def _get_indexer_non_comparable (
5395
5393
self , target : Index , method , unique : Literal [True ] = ...
5396
- ) -> np .ndarray :
5397
- # returned ndarray is np.intp
5394
+ ) -> npt .NDArray [np .intp ]:
5398
5395
...
5399
5396
5400
5397
@overload
5401
5398
def _get_indexer_non_comparable (
5402
5399
self , target : Index , method , unique : Literal [False ]
5403
- ) -> tuple [np .ndarray , np .ndarray ]:
5404
- # both returned ndarrays are np.intp
5400
+ ) -> tuple [npt .NDArray [np .intp ], npt .NDArray [np .intp ]]:
5405
5401
...
5406
5402
5407
5403
@overload
5408
5404
def _get_indexer_non_comparable (
5409
5405
self , target : Index , method , unique : bool = True
5410
- ) -> np .ndarray | tuple [np .ndarray , np .ndarray ]:
5411
- # any returned ndarrays are np.intp
5406
+ ) -> npt .NDArray [np .intp ] | tuple [npt .NDArray [np .intp ], npt .NDArray [np .intp ]]:
5412
5407
...
5413
5408
5414
5409
@final
5415
5410
def _get_indexer_non_comparable (
5416
5411
self , target : Index , method , unique : bool = True
5417
- ) -> np .ndarray | tuple [np .ndarray , np .ndarray ]:
5412
+ ) -> npt . NDArray [ np .intp ] | tuple [npt . NDArray [ np .intp ], npt . NDArray [ np .intp ] ]:
5418
5413
"""
5419
5414
Called from get_indexer or get_indexer_non_unique when the target
5420
5415
is of a non-comparable dtype.
0 commit comments