@@ -3782,17 +3782,23 @@ def get_loc(self, key):
3782
3782
self ._check_indexing_error (key )
3783
3783
raise
3784
3784
3785
- _index_shared_docs [
3786
- "get_indexer"
3787
- ] = """
3785
+ @final
3786
+ def get_indexer (
3787
+ self ,
3788
+ target ,
3789
+ method : ReindexMethod | None = None ,
3790
+ limit : int | None = None ,
3791
+ tolerance = None ,
3792
+ ) -> npt .NDArray [np .intp ]:
3793
+ """
3788
3794
Compute indexer and mask for new index given the current index.
3789
3795
3790
3796
The indexer should be then used as an input to ndarray.take to align the
3791
3797
current data to the new index.
3792
3798
3793
3799
Parameters
3794
3800
----------
3795
- target : %(target_klass)s
3801
+ target : Index
3796
3802
method : {None, 'pad'/'ffill', 'backfill'/'bfill', 'nearest'}, optional
3797
3803
* default: exact matches only.
3798
3804
* pad / ffill: find the PREVIOUS index value if no exact match.
@@ -3819,7 +3825,7 @@ def get_loc(self, key):
3819
3825
Integers from 0 to n - 1 indicating that the index at these
3820
3826
positions matches the corresponding target values. Missing values
3821
3827
in the target are marked by -1.
3822
- %(raises_section)s
3828
+
3823
3829
Notes
3824
3830
-----
3825
3831
Returns -1 for unmatched values, for further explanation see the
@@ -3834,16 +3840,6 @@ def get_loc(self, key):
3834
3840
Notice that the return value is an array of locations in ``index``
3835
3841
and ``x`` is marked by -1, as it is not in ``index``.
3836
3842
"""
3837
-
3838
- @Appender (_index_shared_docs ["get_indexer" ] % _index_doc_kwargs )
3839
- @final
3840
- def get_indexer (
3841
- self ,
3842
- target ,
3843
- method : ReindexMethod | None = None ,
3844
- limit : int | None = None ,
3845
- tolerance = None ,
3846
- ) -> npt .NDArray [np .intp ]:
3847
3843
method = clean_reindex_fill_method (method )
3848
3844
orig_target = target
3849
3845
target = self ._maybe_cast_listlike_indexer (target )
@@ -3898,7 +3894,7 @@ def get_indexer(
3898
3894
3899
3895
return ensure_platform_int (indexer )
3900
3896
3901
- pself , ptarget = self ._maybe_promote (target )
3897
+ pself , ptarget = self ._maybe_downcast_for_indexing (target )
3902
3898
if pself is not self or ptarget is not target :
3903
3899
return pself .get_indexer (
3904
3900
ptarget , method = method , limit = limit , tolerance = tolerance
@@ -4582,7 +4578,7 @@ def join(
4582
4578
4583
4579
if not self ._is_multi and not other ._is_multi :
4584
4580
# We have specific handling for MultiIndex below
4585
- pself , pother = self ._maybe_promote (other )
4581
+ pself , pother = self ._maybe_downcast_for_indexing (other )
4586
4582
if pself is not self or pother is not other :
4587
4583
return pself .join (
4588
4584
pother , how = how , level = level , return_indexers = True , sort = sort
@@ -6046,7 +6042,7 @@ def get_indexer_non_unique(
6046
6042
# that can be matched to Interval scalars.
6047
6043
return self ._get_indexer_non_comparable (target , method = None , unique = False )
6048
6044
6049
- pself , ptarget = self ._maybe_promote (target )
6045
+ pself , ptarget = self ._maybe_downcast_for_indexing (target )
6050
6046
if pself is not self or ptarget is not target :
6051
6047
return pself .get_indexer_non_unique (ptarget )
6052
6048
@@ -6062,8 +6058,8 @@ def get_indexer_non_unique(
6062
6058
# TODO: get_indexer has fastpaths for both Categorical-self and
6063
6059
# Categorical-target. Can we do something similar here?
6064
6060
6065
- # Note: _maybe_promote ensures we never get here with MultiIndex
6066
- # self and non-Multi target
6061
+ # Note: _maybe_downcast_for_indexing ensures we never get here
6062
+ # with MultiIndex self and non-Multi target
6067
6063
tgt_values = target ._get_engine_target ()
6068
6064
if self ._is_multi and target ._is_multi :
6069
6065
engine = self ._engine
@@ -6237,7 +6233,7 @@ def _index_as_unique(self) -> bool:
6237
6233
_requires_unique_msg = "Reindexing only valid with uniquely valued Index objects"
6238
6234
6239
6235
@final
6240
- def _maybe_promote (self , other : Index ) -> tuple [Index , Index ]:
6236
+ def _maybe_downcast_for_indexing (self , other : Index ) -> tuple [Index , Index ]:
6241
6237
"""
6242
6238
When dealing with an object-dtype Index and a non-object Index, see
6243
6239
if we can upcast the object-dtype one to improve performance.
@@ -6278,7 +6274,7 @@ def _maybe_promote(self, other: Index) -> tuple[Index, Index]:
6278
6274
6279
6275
if not is_object_dtype (self .dtype ) and is_object_dtype (other .dtype ):
6280
6276
# Reverse op so we dont need to re-implement on the subclasses
6281
- other , self = other ._maybe_promote (self )
6277
+ other , self = other ._maybe_downcast_for_indexing (self )
6282
6278
6283
6279
return self , other
6284
6280
0 commit comments