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

CLN: Changed the behavior of Series.__[gs]etitem__ with an integer slice on objects with a floating-dtype index to a positional instead of label-based slicing #58449

Closed
Changes from 1 commit
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
15 changes: 2 additions & 13 deletions pandas/core/indexes/base.py
Expand Up @@ -3842,20 +3842,9 @@ def _convert_slice_indexer(self, key: slice, kind: Literal["loc", "getitem"]):
# We always treat __getitem__ slicing as label-based
# translate to locations
if kind == "getitem" and is_index_slice and not start == stop and step != 0:
# exclude step=0 from the warning because it will raise anyway
# start/stop both None e.g. [:] or [::-1] won't change.
# exclude start==stop since it will be empty either way, or
# will be [:] or [::-1] which won't change
warnings.warn(
# GH#49612
"The behavior of obj[i:j] with a float-dtype index is "
"deprecated. In a future version, this will be treated as "
"positional instead of label-based. For label-based slicing, "
"use obj.loc[i:j] instead",
FutureWarning,
stacklevel=find_stack_level(),
raise TypeError(
Copy link
Member

Choose a reason for hiding this comment

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

It’s not unsupported. The point is to change the behavior to not special-case here

Copy link
Contributor Author

@natmokval natmokval Apr 27, 2024

Choose a reason for hiding this comment

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

Thanks for helping me with this PR. I corrected my mistake, fixed tests, and added a note to v3.0.0

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@jbrockmendel could you please take a look at my changes?

"Using of obj[i:j] with a float-dtype index is not supported"
)
return self.slice_indexer(start, stop, step)

if kind == "getitem":
# called from the getitem slicers, validate that we are in fact integers
Expand Down