@@ -3077,7 +3077,7 @@ def intersection(self, other, sort=False):
3077
3077
return Index ([], name = result_name )
3078
3078
3079
3079
elif not is_dtype_equal (self .dtype , other .dtype ):
3080
- dtype = find_common_type ([ self .dtype , other . dtype ] )
3080
+ dtype = self ._find_common_type_compat ( other )
3081
3081
this = self .astype (dtype , copy = False )
3082
3082
other = other .astype (dtype , copy = False )
3083
3083
return this .intersection (other , sort = sort )
@@ -3429,6 +3429,10 @@ def get_indexer(
3429
3429
ptarget , method = method , limit = limit , tolerance = tolerance
3430
3430
)
3431
3431
3432
+ if is_dtype_equal (self .dtype , target .dtype ) and self .equals (target ):
3433
+ # Only call equals if we have same dtype to avoid inference/casting
3434
+ return np .arange (len (target ), dtype = np .intp )
3435
+
3432
3436
return self ._get_indexer (target , method , limit , tolerance )
3433
3437
3434
3438
def _get_indexer (
@@ -3951,8 +3955,9 @@ def join(
3951
3955
return join_index , lidx , ridx
3952
3956
3953
3957
if not is_dtype_equal (self .dtype , other .dtype ):
3954
- this = self .astype ("O" )
3955
- other = other .astype ("O" )
3958
+ dtype = self ._find_common_type_compat (other )
3959
+ this = self .astype (dtype , copy = False )
3960
+ other = other .astype (dtype , copy = False )
3956
3961
return this .join (other , how = how , return_indexers = True )
3957
3962
3958
3963
_validate_join_method (how )
@@ -5230,6 +5235,8 @@ def get_indexer_non_unique(self, target) -> tuple[np.ndarray, np.ndarray]:
5230
5235
that = target .astype (dtype , copy = False )
5231
5236
return this .get_indexer_non_unique (that )
5232
5237
5238
+ # Note: _maybe_promote ensures we never get here with MultiIndex
5239
+ # self and non-Multi target
5233
5240
tgt_values = target ._get_engine_target ()
5234
5241
5235
5242
indexer , missing = self ._engine .get_indexer_non_unique (tgt_values )
@@ -5962,8 +5969,7 @@ def insert(self, loc: int, item) -> Index:
5962
5969
try :
5963
5970
item = self ._validate_fill_value (item )
5964
5971
except TypeError :
5965
- inferred , _ = infer_dtype_from (item )
5966
- dtype = find_common_type ([self .dtype , inferred ])
5972
+ dtype = self ._find_common_type_compat (item )
5967
5973
return self .astype (dtype ).insert (loc , item )
5968
5974
5969
5975
arr = np .asarray (self )
0 commit comments