From 7c17b37f0e2e85a0d5b4102313c3a5f41974e3d8 Mon Sep 17 00:00:00 2001 From: Brock Date: Mon, 13 Feb 2023 07:16:18 -0800 Subject: [PATCH] CLN: indexing checks --- pandas/core/indexes/base.py | 15 ++++++++------- pandas/core/series.py | 2 +- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/pandas/core/indexes/base.py b/pandas/core/indexes/base.py index 363bfe76d40fb..2b55e0c8c1d0e 100644 --- a/pandas/core/indexes/base.py +++ b/pandas/core/indexes/base.py @@ -3732,10 +3732,11 @@ def get_indexer( # Only call equals if we have same dtype to avoid inference/casting return np.arange(len(target), dtype=np.intp) - if not is_dtype_equal(self.dtype, target.dtype) and not is_interval_dtype( - self.dtype - ): - # IntervalIndex gets special treatment for partial-indexing + if not is_dtype_equal( + self.dtype, target.dtype + ) and not self._should_partial_index(target): + # _should_partial_index e.g. IntervalIndex with numeric scalars + # that can be matched to Interval scalars. dtype = self._find_common_type_compat(target) this = self.astype(dtype, copy=False) @@ -5739,9 +5740,9 @@ def get_indexer_non_unique( target = ensure_index(target) target = self._maybe_cast_listlike_indexer(target) - if not self._should_compare(target) and not is_interval_dtype(self.dtype): - # IntervalIndex get special treatment bc numeric scalars can be - # matched to Interval scalars + if not self._should_compare(target) and not self._should_partial_index(target): + # _should_partial_index e.g. IntervalIndex with numeric scalars + # that can be matched to Interval scalars. return self._get_indexer_non_comparable(target, method=None, unique=False) pself, ptarget = self._maybe_promote(target) diff --git a/pandas/core/series.py b/pandas/core/series.py index 8934b7c65130b..78c6cc9f94ed2 100644 --- a/pandas/core/series.py +++ b/pandas/core/series.py @@ -1111,7 +1111,7 @@ def __setitem__(self, key, value) -> None: except KeyError: # We have a scalar (or for MultiIndex or object-dtype, scalar-like) # key that is not present in self.index. - if is_integer(key) and self.index.inferred_type != "integer": + if is_integer(key): if not self.index._should_fallback_to_positional: # GH#33469 self.loc[key] = value