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

Comment From: rhshadrach

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.

Comment From: rhshadrach

Another common non-ambiguous use case is Boolean masking.

Comment From: jbrockmendel

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

Comment From: jbrockmendel

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

Comment From: rhshadrach

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.

Comment From: jbrockmendel

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