13
13
Sequence ,
14
14
TypeVar ,
15
15
cast ,
16
+ overload ,
16
17
)
17
18
import warnings
18
19
159
160
)
160
161
161
162
if TYPE_CHECKING :
163
+ from typing import Literal
164
+
162
165
from pandas import (
163
166
CategoricalIndex ,
164
167
DataFrame ,
@@ -5212,7 +5215,8 @@ def set_value(self, arr, key, value):
5212
5215
"""
5213
5216
5214
5217
@Appender (_index_shared_docs ["get_indexer_non_unique" ] % _index_doc_kwargs )
5215
- def get_indexer_non_unique (self , target ):
5218
+ def get_indexer_non_unique (self , target ) -> tuple [np .ndarray , np .ndarray ]:
5219
+ # both returned ndarrays are np.intp
5216
5220
target = ensure_index (target )
5217
5221
5218
5222
if not self ._should_compare (target ) and not is_interval_dtype (self .dtype ):
@@ -5236,7 +5240,7 @@ def get_indexer_non_unique(self, target):
5236
5240
tgt_values = target ._get_engine_target ()
5237
5241
5238
5242
indexer , missing = self ._engine .get_indexer_non_unique (tgt_values )
5239
- return ensure_platform_int (indexer ), missing
5243
+ return ensure_platform_int (indexer ), ensure_platform_int ( missing )
5240
5244
5241
5245
@final
5242
5246
def get_indexer_for (self , target , ** kwargs ) -> np .ndarray :
@@ -5256,8 +5260,31 @@ def get_indexer_for(self, target, **kwargs) -> np.ndarray:
5256
5260
indexer , _ = self .get_indexer_non_unique (target )
5257
5261
return indexer
5258
5262
5263
+ @overload
5264
+ def _get_indexer_non_comparable (
5265
+ self , target : Index , method , unique : Literal [True ] = ...
5266
+ ) -> np .ndarray :
5267
+ # returned ndarray is np.intp
5268
+ ...
5269
+
5270
+ @overload
5271
+ def _get_indexer_non_comparable (
5272
+ self , target : Index , method , unique : Literal [False ]
5273
+ ) -> tuple [np .ndarray , np .ndarray ]:
5274
+ # both returned ndarrays are np.intp
5275
+ ...
5276
+
5277
+ @overload
5278
+ def _get_indexer_non_comparable (
5279
+ self , target : Index , method , unique : bool = True
5280
+ ) -> np .ndarray | tuple [np .ndarray , np .ndarray ]:
5281
+ # any returned ndarrays are np.intp
5282
+ ...
5283
+
5259
5284
@final
5260
- def _get_indexer_non_comparable (self , target : Index , method , unique : bool = True ):
5285
+ def _get_indexer_non_comparable (
5286
+ self , target : Index , method , unique : bool = True
5287
+ ) -> np .ndarray | tuple [np .ndarray , np .ndarray ]:
5261
5288
"""
5262
5289
Called from get_indexer or get_indexer_non_unique when the target
5263
5290
is of a non-comparable dtype.
0 commit comments