@@ -395,15 +395,17 @@ def unique(self, level=None):
395
395
# of result, not self.
396
396
return type (self )._simple_new (result , name = self .name )
397
397
398
- def reindex (self , target , method = None , level = None , limit = None , tolerance = None ):
398
+ def reindex (
399
+ self , target , method = None , level = None , limit = None , tolerance = None
400
+ ) -> tuple [Index , np .ndarray | None ]:
399
401
"""
400
402
Create index with target's values (move/add/delete values as necessary)
401
403
402
404
Returns
403
405
-------
404
406
new_index : pd.Index
405
407
Resulting index
406
- indexer : np.ndarray or None
408
+ indexer : np.ndarray[np.intp] or None
407
409
Indices of output values in original index
408
410
409
411
"""
@@ -440,7 +442,7 @@ def reindex(self, target, method=None, level=None, limit=None, tolerance=None):
440
442
if not isinstance (cats , CategoricalIndex ) or (cats == - 1 ).any ():
441
443
# coerce to a regular index here!
442
444
result = Index (np .array (self ), name = self .name )
443
- new_target , indexer , _ = result ._reindex_non_unique (np . array ( target ) )
445
+ new_target , indexer , _ = result ._reindex_non_unique (target )
444
446
else :
445
447
446
448
codes = new_target .codes .copy ()
@@ -462,25 +464,34 @@ def reindex(self, target, method=None, level=None, limit=None, tolerance=None):
462
464
463
465
return new_target , indexer
464
466
465
- def _reindex_non_unique (self , target ):
467
+ # error: Return type "Tuple[Index, Optional[ndarray], Optional[ndarray]]"
468
+ # of "_reindex_non_unique" incompatible with return type
469
+ # "Tuple[Index, ndarray, Optional[ndarray]]" in supertype "Index"
470
+ def _reindex_non_unique ( # type: ignore[override]
471
+ self , target : Index
472
+ ) -> tuple [Index , np .ndarray | None , np .ndarray | None ]:
466
473
"""
467
474
reindex from a non-unique; which CategoricalIndex's are almost
468
475
always
469
476
"""
477
+ # TODO: rule out `indexer is None` here to make the signature
478
+ # match the parent class's signature. This should be equivalent
479
+ # to ruling out `self.equals(target)`
470
480
new_target , indexer = self .reindex (target )
471
481
new_indexer = None
472
482
473
483
check = indexer == - 1
474
- if check .any ():
475
- new_indexer = np .arange (len (self .take (indexer )))
484
+ # error: Item "bool" of "Union[Any, bool]" has no attribute "any"
485
+ if check .any (): # type: ignore[union-attr]
486
+ new_indexer = np .arange (len (self .take (indexer )), dtype = np .intp )
476
487
new_indexer [check ] = - 1
477
488
478
489
cats = self .categories .get_indexer (target )
479
490
if not (cats == - 1 ).any ():
480
491
# .reindex returns normal Index. Revert to CategoricalIndex if
481
492
# all targets are included in my categories
482
- new_target = Categorical (new_target , dtype = self .dtype )
483
- new_target = type (self )._simple_new (new_target , name = self .name )
493
+ cat = Categorical (new_target , dtype = self .dtype )
494
+ new_target = type (self )._simple_new (cat , name = self .name )
484
495
485
496
return new_target , indexer , new_indexer
486
497
0 commit comments