@@ -3289,11 +3289,10 @@ def get_indexer(
3289
3289
if not self ._index_as_unique :
3290
3290
raise InvalidIndexError (self ._requires_unique_msg )
3291
3291
3292
- # Treat boolean labels passed to a numeric index as not found. Without
3293
- # this fix False and True would be treated as 0 and 1 respectively.
3294
- # (GH #16877)
3295
- if target .is_boolean () and self .is_numeric ():
3296
- return ensure_platform_int (np .repeat (- 1 , target .size ))
3292
+ if not self ._should_compare (target ) and not is_interval_dtype (self .dtype ):
3293
+ # IntervalIndex get special treatment bc numeric scalars can be
3294
+ # matched to Interval scalars
3295
+ return self ._get_indexer_non_comparable (target , method = method , unique = True )
3297
3296
3298
3297
pself , ptarget = self ._maybe_promote (target )
3299
3298
if pself is not self or ptarget is not target :
@@ -3310,8 +3309,9 @@ def _get_indexer(
3310
3309
tolerance = self ._convert_tolerance (tolerance , target )
3311
3310
3312
3311
if not is_dtype_equal (self .dtype , target .dtype ):
3313
- this = self .astype (object )
3314
- target = target .astype (object )
3312
+ dtype = find_common_type ([self .dtype , target .dtype ])
3313
+ this = self .astype (dtype , copy = False )
3314
+ target = target .astype (dtype , copy = False )
3315
3315
return this .get_indexer (
3316
3316
target , method = method , limit = limit , tolerance = tolerance
3317
3317
)
@@ -5060,19 +5060,15 @@ def set_value(self, arr, key, value):
5060
5060
def get_indexer_non_unique (self , target ):
5061
5061
target = ensure_index (target )
5062
5062
5063
- if target .is_boolean () and self .is_numeric ():
5064
- # Treat boolean labels passed to a numeric index as not found. Without
5065
- # this fix False and True would be treated as 0 and 1 respectively.
5066
- # (GH #16877)
5063
+ if not self ._should_compare (target ) and not is_interval_dtype (self .dtype ):
5064
+ # IntervalIndex get special treatment bc numeric scalars can be
5065
+ # matched to Interval scalars
5067
5066
return self ._get_indexer_non_comparable (target , method = None , unique = False )
5068
5067
5069
5068
pself , ptarget = self ._maybe_promote (target )
5070
5069
if pself is not self or ptarget is not target :
5071
5070
return pself .get_indexer_non_unique (ptarget )
5072
5071
5073
- if not self ._should_compare (target ):
5074
- return self ._get_indexer_non_comparable (target , method = None , unique = False )
5075
-
5076
5072
if not is_dtype_equal (self .dtype , target .dtype ):
5077
5073
# TODO: if object, could use infer_dtype to preempt costly
5078
5074
# conversion if still non-comparable?
@@ -5193,6 +5189,15 @@ def _should_compare(self, other: Index) -> bool:
5193
5189
"""
5194
5190
Check if `self == other` can ever have non-False entries.
5195
5191
"""
5192
+
5193
+ if (other .is_boolean () and self .is_numeric ()) or (
5194
+ self .is_boolean () and other .is_numeric ()
5195
+ ):
5196
+ # GH#16877 Treat boolean labels passed to a numeric index as not
5197
+ # found. Without this fix False and True would be treated as 0 and 1
5198
+ # respectively.
5199
+ return False
5200
+
5196
5201
other = unpack_nested_dtype (other )
5197
5202
dtype = other .dtype
5198
5203
return self ._is_comparable_dtype (dtype ) or is_object_dtype (dtype )
0 commit comments