Skip to content

Commit 55b4edd

Browse files
authored
REF: move casting from Index._get_indexer to Index.get_indexer (#42308)
1 parent 6d37573 commit 55b4edd

File tree

2 files changed

+12
-13
lines changed

2 files changed

+12
-13
lines changed

pandas/core/indexes/base.py

+12-9
Original file line numberDiff line numberDiff line change
@@ -3486,6 +3486,18 @@ def get_indexer(
34863486
# Only call equals if we have same dtype to avoid inference/casting
34873487
return np.arange(len(target), dtype=np.intp)
34883488

3489+
if not is_dtype_equal(self.dtype, target.dtype) and not is_interval_dtype(
3490+
self.dtype
3491+
):
3492+
# IntervalIndex gets special treatment for partial-indexing
3493+
dtype = self._find_common_type_compat(target)
3494+
3495+
this = self.astype(dtype, copy=False)
3496+
target = target.astype(dtype, copy=False)
3497+
return this._get_indexer(
3498+
target, method=method, limit=limit, tolerance=tolerance
3499+
)
3500+
34893501
return self._get_indexer(target, method, limit, tolerance)
34903502

34913503
def _get_indexer(
@@ -3498,15 +3510,6 @@ def _get_indexer(
34983510
if tolerance is not None:
34993511
tolerance = self._convert_tolerance(tolerance, target)
35003512

3501-
if not is_dtype_equal(self.dtype, target.dtype):
3502-
dtype = self._find_common_type_compat(target)
3503-
3504-
this = self.astype(dtype, copy=False)
3505-
target = target.astype(dtype, copy=False)
3506-
return this.get_indexer(
3507-
target, method=method, limit=limit, tolerance=tolerance
3508-
)
3509-
35103513
if method in ["pad", "backfill"]:
35113514
indexer = self._get_fill_indexer(target, method, limit, tolerance)
35123515
elif method == "nearest":

pandas/core/indexes/range.py

-4
Original file line numberDiff line numberDiff line change
@@ -409,10 +409,6 @@ def _get_indexer(
409409
reverse = self._range[::-1]
410410
start, stop, step = reverse.start, reverse.stop, reverse.step
411411

412-
if not is_signed_integer_dtype(target):
413-
# checks/conversions/roundings are delegated to general method
414-
return super()._get_indexer(target, method=method, tolerance=tolerance)
415-
416412
target_array = np.asarray(target)
417413
locs = target_array - start
418414
valid = (locs % step == 0) & (locs >= 0) & (target_array < stop)

0 commit comments

Comments
 (0)