Skip to content

Commit 70515df

Browse files
authored
CLN: idiomatic indexing checks (#51360)
CLN: indexing checks
1 parent 25a0578 commit 70515df

File tree

2 files changed

+9
-8
lines changed

2 files changed

+9
-8
lines changed

pandas/core/indexes/base.py

+8-7
Original file line numberDiff line numberDiff line change
@@ -3732,10 +3732,11 @@ def get_indexer(
37323732
# Only call equals if we have same dtype to avoid inference/casting
37333733
return np.arange(len(target), dtype=np.intp)
37343734

3735-
if not is_dtype_equal(self.dtype, target.dtype) and not is_interval_dtype(
3736-
self.dtype
3737-
):
3738-
# IntervalIndex gets special treatment for partial-indexing
3735+
if not is_dtype_equal(
3736+
self.dtype, target.dtype
3737+
) and not self._should_partial_index(target):
3738+
# _should_partial_index e.g. IntervalIndex with numeric scalars
3739+
# that can be matched to Interval scalars.
37393740
dtype = self._find_common_type_compat(target)
37403741

37413742
this = self.astype(dtype, copy=False)
@@ -5739,9 +5740,9 @@ def get_indexer_non_unique(
57395740
target = ensure_index(target)
57405741
target = self._maybe_cast_listlike_indexer(target)
57415742

5742-
if not self._should_compare(target) and not is_interval_dtype(self.dtype):
5743-
# IntervalIndex get special treatment bc numeric scalars can be
5744-
# matched to Interval scalars
5743+
if not self._should_compare(target) and not self._should_partial_index(target):
5744+
# _should_partial_index e.g. IntervalIndex with numeric scalars
5745+
# that can be matched to Interval scalars.
57455746
return self._get_indexer_non_comparable(target, method=None, unique=False)
57465747

57475748
pself, ptarget = self._maybe_promote(target)

pandas/core/series.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1111,7 +1111,7 @@ def __setitem__(self, key, value) -> None:
11111111
except KeyError:
11121112
# We have a scalar (or for MultiIndex or object-dtype, scalar-like)
11131113
# key that is not present in self.index.
1114-
if is_integer(key) and self.index.inferred_type != "integer":
1114+
if is_integer(key):
11151115
if not self.index._should_fallback_to_positional:
11161116
# GH#33469
11171117
self.loc[key] = value

0 commit comments

Comments
 (0)