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: Series.__getitem__, Series.__setitem__ #50617

Open
jbrockmendel opened this issue Jan 7, 2023 · 6 comments
Open

DEPR: Series.__getitem__, Series.__setitem__ #50617

jbrockmendel opened this issue Jan 7, 2023 · 6 comments
Labels
Deprecate Functionality to remove in pandas Needs Discussion Requires discussion from core team before further action

Comments

@jbrockmendel
Copy link
Member

jbrockmendel commented Jan 7, 2023

Trying to guess whether e.g. ser[2], ser[:2] is intended to be positional or label-based is a hassle, and in the slicing case we are inconsistent about it. Let's get rid of this problem once and for all by deprecating these and telling users to use loc or iloc instead.

Discussed in #49612

@jbrockmendel jbrockmendel added Bug Needs Triage Issue that has not been reviewed by a pandas team member Deprecate Functionality to remove in pandas labels Jan 7, 2023
@rhshadrach
Copy link
Member

rhshadrach commented Jan 7, 2023

There is probably a lot of code out there using __getitem__ and __setitem__ in ways that don't require guessing. Admittedly this includes my own, but my usage is maybe atypical in that almost none of my indices are integral.

Is having __getitem__ and __setitem__ be an alias of loc doable? The reason I'd suggest loc instead of iloc is that I think all other __getitem__ and __setitem__ for pandas objects (e.g. DataFrame, DataFrameGroupBy) are label-based. We could emit warnings for any user specifying integral arguments that it is ambiguous, informing them to switch to loc or iloc. The deprecation would certainly be a bit more complex, but less noisy for those using non-integral arguments.

@rhshadrach
Copy link
Member

Another common non-ambiguous use case is Boolean masking.

@jbrockmendel
Copy link
Member Author

even boolean masking can manage to be ambiguous if you have bools in your index

@jbrockmendel jbrockmendel added Needs Discussion Requires discussion from core team before further action and removed Bug Needs Triage Issue that has not been reviewed by a pandas team member labels Jan 12, 2023
@jbrockmendel
Copy link
Member Author

Another option would be to make getitem/setitem always label-based (after deprecation cycle), which would match the DataFrame behavior

@rhshadrach
Copy link
Member

rhshadrach commented May 4, 2023

Would that also deprecate using Boolean masks? I'm +1 only allowing for label-based or Boolean masks, but hesitant if we aren't going to allow Boolean masks as well.

@jbrockmendel
Copy link
Member Author

Would that also deprecate using Boolean masks?

no it would not. It would leave the ambiguous corner-case when you have a bool-dtype Index

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Deprecate Functionality to remove in pandas Needs Discussion Requires discussion from core team before further action
Projects
None yet
Development

No branches or pull requests

2 participants