12
12
13
13
from pandas ._libs import index as libindex
14
14
from pandas ._typing import (
15
- ArrayLike ,
16
15
Dtype ,
17
16
DtypeObj ,
18
17
)
19
- from pandas .util ._decorators import (
20
- Appender ,
21
- doc ,
22
- )
18
+ from pandas .util ._decorators import doc
23
19
24
20
from pandas .core .dtypes .common import (
25
- ensure_platform_int ,
26
21
is_categorical_dtype ,
27
22
is_scalar ,
28
23
)
41
36
import pandas .core .indexes .base as ibase
42
37
from pandas .core .indexes .base import (
43
38
Index ,
44
- _index_shared_docs ,
45
39
maybe_extract_name ,
46
40
)
47
41
from pandas .core .indexes .extension import (
@@ -492,38 +486,9 @@ def _maybe_cast_indexer(self, key) -> int:
492
486
return - 1
493
487
raise
494
488
495
- def _get_indexer (
496
- self ,
497
- target : Index ,
498
- method : str | None = None ,
499
- limit : int | None = None ,
500
- tolerance = None ,
501
- ) -> np .ndarray :
502
- # returned ndarray is np.intp
503
-
504
- if self .equals (target ):
505
- return np .arange (len (self ), dtype = "intp" )
506
-
507
- return self ._get_indexer_non_unique (target ._values )[0 ]
508
-
509
- @Appender (_index_shared_docs ["get_indexer_non_unique" ] % _index_doc_kwargs )
510
- def get_indexer_non_unique (self , target ) -> tuple [np .ndarray , np .ndarray ]:
511
- # both returned ndarrays are np.intp
512
- target = ibase .ensure_index (target )
513
- return self ._get_indexer_non_unique (target ._values )
514
-
515
- def _get_indexer_non_unique (
516
- self , values : ArrayLike
517
- ) -> tuple [np .ndarray , np .ndarray ]:
518
- # both returned ndarrays are np.intp
519
- """
520
- get_indexer_non_unique but after unrapping the target Index object.
521
- """
522
- # Note: we use engine.get_indexer_non_unique for get_indexer in addition
523
- # to get_indexer_non_unique because, even if `target` is unique, any
524
- # non-category entries in it will be encoded as -1 so `codes` may
525
- # not be unique.
526
-
489
+ def _maybe_cast_listlike_indexer (self , values ) -> CategoricalIndex :
490
+ if isinstance (values , CategoricalIndex ):
491
+ values = values ._data
527
492
if isinstance (values , Categorical ):
528
493
# Indexing on codes is more efficient if categories are the same,
529
494
# so we can apply some optimizations based on the degree of
@@ -532,9 +497,9 @@ def _get_indexer_non_unique(
532
497
codes = cat ._codes
533
498
else :
534
499
codes = self .categories .get_indexer (values )
535
-
536
- indexer , missing = self ._engine . get_indexer_non_unique (codes )
537
- return ensure_platform_int ( indexer ), ensure_platform_int ( missing )
500
+ codes = codes . astype ( self . codes . dtype , copy = False )
501
+ cat = self ._data . _from_backing_data (codes )
502
+ return type ( self ). _simple_new ( cat )
538
503
539
504
# --------------------------------------------------------------------
540
505
0 commit comments