Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DEPR: Move Numericindex._convert_slice_indexer & ._maybe_cast_slice_bound #50989

Merged
merged 3 commits into from
Jan 27, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 9 additions & 4 deletions pandas/core/indexes/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -3983,6 +3983,13 @@ def _convert_slice_indexer(self, key: slice, kind: str_t):
# potentially cast the bounds to integers
start, stop, step = key.start, key.stop, key.step

# TODO(GH#50617): once Series.__[gs]etitem__ is removed we should be able
# to simplify this.
if is_float_dtype(self.dtype):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

need to specify numpy dtype

# We always treat __getitem__ slicing as label-based
# translate to locations
return self.slice_indexer(start, stop, step)

# figure out if this is a positional indexer
def is_int(v):
return v is None or is_integer(v)
Expand Down Expand Up @@ -6284,11 +6291,9 @@ def _maybe_cast_slice_bound(self, label, side: str_t):
"""

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

if is_extension_array_dtype(self.dtype) and is_numeric_dtype(self.dtype):
if is_numeric_dtype(self.dtype):
return self._maybe_cast_indexer(label)

# reject them, if index does not contain label
Expand Down
19 changes: 0 additions & 19 deletions pandas/core/indexes/numeric.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@

from pandas.core.dtypes.common import (
is_dtype_equal,
is_float_dtype,
is_integer_dtype,
is_numeric_dtype,
is_scalar,
Expand Down Expand Up @@ -170,24 +169,6 @@ def _ensure_dtype(cls, dtype: Dtype | None) -> np.dtype | None:
def _should_fallback_to_positional(self) -> bool:
return False

@doc(Index._convert_slice_indexer)
def _convert_slice_indexer(self, key: slice, kind: str):
# TODO(GH#50617): once Series.__[gs]etitem__ is removed we should be able
# to simplify this.
if is_float_dtype(self.dtype):
assert kind in ["loc", "getitem"]

# We always treat __getitem__ slicing as label-based
# translate to locations
return self.slice_indexer(key.start, key.stop, key.step)

return super()._convert_slice_indexer(key, kind=kind)

@doc(Index._maybe_cast_slice_bound)
def _maybe_cast_slice_bound(self, label, side: str):
# we will try to coerce to integers
return self._maybe_cast_indexer(label)

# ----------------------------------------------------------------

@classmethod
Expand Down