Skip to content

Commit 22de62c

Browse files
authored
DEPR: Move Numericindex._convert_slice_indexer & ._maybe_cast_slice_bound (pandas-dev#50989)
1 parent f4d1cd5 commit 22de62c

File tree

2 files changed

+9
-23
lines changed

2 files changed

+9
-23
lines changed

pandas/core/indexes/base.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4009,6 +4009,13 @@ def _convert_slice_indexer(self, key: slice, kind: str_t):
40094009
# potentially cast the bounds to integers
40104010
start, stop, step = key.start, key.stop, key.step
40114011

4012+
# TODO(GH#50617): once Series.__[gs]etitem__ is removed we should be able
4013+
# to simplify this.
4014+
if isinstance(self.dtype, np.dtype) and is_float_dtype(self.dtype):
4015+
# We always treat __getitem__ slicing as label-based
4016+
# translate to locations
4017+
return self.slice_indexer(start, stop, step)
4018+
40124019
# figure out if this is a positional indexer
40134020
def is_int(v):
40144021
return v is None or is_integer(v)
@@ -6314,11 +6321,9 @@ def _maybe_cast_slice_bound(self, label, side: str_t):
63146321
"""
63156322

63166323
# We are a plain index here (sub-class override this method if they
6317-
# wish to have special treatment for floats/ints, e.g. NumericIndex and
6318-
# datetimelike Indexes
6319-
# Special case numeric EA Indexes, since they are not handled by NumericIndex
6324+
# wish to have special treatment for floats/ints, e.g. datetimelike Indexes
63206325

6321-
if is_extension_array_dtype(self.dtype) and is_numeric_dtype(self.dtype):
6326+
if is_numeric_dtype(self.dtype):
63226327
return self._maybe_cast_indexer(label)
63236328

63246329
# reject them, if index does not contain label

pandas/core/indexes/numeric.py

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212

1313
from pandas.core.dtypes.common import (
1414
is_dtype_equal,
15-
is_float_dtype,
1615
is_integer_dtype,
1716
is_numeric_dtype,
1817
is_scalar,
@@ -170,24 +169,6 @@ def _ensure_dtype(cls, dtype: Dtype | None) -> np.dtype | None:
170169
def _should_fallback_to_positional(self) -> bool:
171170
return False
172171

173-
@doc(Index._convert_slice_indexer)
174-
def _convert_slice_indexer(self, key: slice, kind: str):
175-
# TODO(GH#50617): once Series.__[gs]etitem__ is removed we should be able
176-
# to simplify this.
177-
if is_float_dtype(self.dtype):
178-
assert kind in ["loc", "getitem"]
179-
180-
# We always treat __getitem__ slicing as label-based
181-
# translate to locations
182-
return self.slice_indexer(key.start, key.stop, key.step)
183-
184-
return super()._convert_slice_indexer(key, kind=kind)
185-
186-
@doc(Index._maybe_cast_slice_bound)
187-
def _maybe_cast_slice_bound(self, label, side: str):
188-
# we will try to coerce to integers
189-
return self._maybe_cast_indexer(label)
190-
191172
# ----------------------------------------------------------------
192173

193174
@classmethod

0 commit comments

Comments
 (0)