@@ -906,35 +906,35 @@ def get_indexer(
906
906
)
907
907
raise InvalidIndexError (msg )
908
908
909
- target = ensure_index (target )
909
+ target_as_index = ensure_index (target )
910
910
911
- if isinstance (target , IntervalIndex ):
911
+ if isinstance (target_as_index , IntervalIndex ):
912
912
# equal indexes -> 1:1 positional match
913
- if self .equals (target ):
913
+ if self .equals (target_as_index ):
914
914
return np .arange (len (self ), dtype = "intp" )
915
915
916
916
# different closed or incompatible subtype -> no matches
917
917
common_subtype = find_common_type (
918
- [self .dtype .subtype , target .dtype .subtype ]
918
+ [self .dtype .subtype , target_as_index .dtype .subtype ]
919
919
)
920
- if self .closed != target .closed or is_object_dtype (common_subtype ):
921
- return np .repeat (np .intp (- 1 ), len (target ))
920
+ if self .closed != target_as_index .closed or is_object_dtype (common_subtype ):
921
+ return np .repeat (np .intp (- 1 ), len (target_as_index ))
922
922
923
- # non-overlapping -> at most one match per interval in target
923
+ # non-overlapping -> at most one match per interval in target_as_index
924
924
# want exact matches -> need both left/right to match, so defer to
925
925
# left/right get_indexer, compare elementwise, equality -> match
926
- left_indexer = self .left .get_indexer (target .left )
927
- right_indexer = self .right .get_indexer (target .right )
926
+ left_indexer = self .left .get_indexer (target_as_index .left )
927
+ right_indexer = self .right .get_indexer (target_as_index .right )
928
928
indexer = np .where (left_indexer == right_indexer , left_indexer , - 1 )
929
- elif not is_object_dtype (target ):
929
+ elif not is_object_dtype (target_as_index ):
930
930
# homogeneous scalar index: use IntervalTree
931
- target = self ._maybe_convert_i8 (target )
932
- indexer = self ._engine .get_indexer (target .values )
931
+ target_as_index = self ._maybe_convert_i8 (target_as_index )
932
+ indexer = self ._engine .get_indexer (target_as_index .values )
933
933
else :
934
934
# heterogeneous scalar index: defer elementwise to get_loc
935
935
# (non-overlapping so get_loc guarantees scalar of KeyError)
936
936
indexer = []
937
- for key in target :
937
+ for key in target_as_index :
938
938
try :
939
939
loc = self .get_loc (key )
940
940
except KeyError :
@@ -947,21 +947,26 @@ def get_indexer(
947
947
def get_indexer_non_unique (
948
948
self , target : AnyArrayLike
949
949
) -> Tuple [np .ndarray , np .ndarray ]:
950
- target = ensure_index (target )
950
+ target_as_index = ensure_index (target )
951
951
952
- # check that target IntervalIndex is compatible
953
- if isinstance (target , IntervalIndex ):
952
+ # check that target_as_index IntervalIndex is compatible
953
+ if isinstance (target_as_index , IntervalIndex ):
954
954
common_subtype = find_common_type (
955
- [self .dtype .subtype , target .dtype .subtype ]
955
+ [self .dtype .subtype , target_as_index .dtype .subtype ]
956
956
)
957
- if self .closed != target .closed or is_object_dtype (common_subtype ):
957
+ if self .closed != target_as_index .closed or is_object_dtype (common_subtype ):
958
958
# different closed or incompatible subtype -> no matches
959
- return np .repeat (- 1 , len (target )), np .arange (len (target ))
959
+ return (
960
+ np .repeat (- 1 , len (target_as_index )),
961
+ np .arange (len (target_as_index )),
962
+ )
960
963
961
- if is_object_dtype (target ) or isinstance (target , IntervalIndex ):
962
- # target might contain intervals: defer elementwise to get_loc
964
+ if is_object_dtype (target_as_index ) or isinstance (
965
+ target_as_index , IntervalIndex
966
+ ):
967
+ # target_as_index might contain intervals: defer elementwise to get_loc
963
968
indexer , missing = [], []
964
- for i , key in enumerate (target ):
969
+ for i , key in enumerate (target_as_index ):
965
970
try :
966
971
locs = self .get_loc (key )
967
972
if isinstance (locs , slice ):
@@ -973,8 +978,10 @@ def get_indexer_non_unique(
973
978
indexer .append (locs )
974
979
indexer = np .concatenate (indexer )
975
980
else :
976
- target = self ._maybe_convert_i8 (target )
977
- indexer , missing = self ._engine .get_indexer_non_unique (target .values )
981
+ target_as_index = self ._maybe_convert_i8 (target_as_index )
982
+ indexer , missing = self ._engine .get_indexer_non_unique (
983
+ target_as_index .values
984
+ )
978
985
979
986
return ensure_platform_int (indexer ), ensure_platform_int (missing )
980
987
0 commit comments