-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
API: __getitem__[int] vs __setitem__[int] with Float64Index #33469
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
Comments
This API is certainly a mess .. ;) The proposal is to change the setitem case where it fallbacks to positional to also be strictly label-based? But so the integer would also be interpreted as label, and thus do enlargement in case it is not yet present? Using your example series:
I was first thinking this would be a relatively safe change, since it right now already tries label-based for setitem first (so if the integer key is present as a label, it would already do label-based now). So the potential difference in behaviour is only when the label is not present. Right now that can update a value, but in the future add another value like the above? Which is kind of silently resulting in different data. We could also deprecate integer keys for setitem first or raise an error for it? |
Do you mean "deprecate ever treating integer as a label for Float64Index"? Or "deprecate allowing ser[integer] with Float64Index"? The first seems reasonable. I'd be OK with "integers are always considered labels" or "integers are always considered positional", so there is no question of fall-back behavior. |
Options that come to mind for fixing this:
|
Currently I think
For that last reason (value-dependent behavior), I wouldn't go for this.
What's the behavioral consequence of this? So that if the key (cast to float) is not present, always use positional? Is a 4th option to change Float64Index._should_fallback_to_positional to always return False? (like it is for Int64Index?) |
Note: in all the options described above, we are changing in
If we do that, and add in
(without the extra clause in
That is the status quo for _should_fallback_to_positional. If we change the line in
|
IIUC I think integers should always be label based for FloatIndex. so this means deprecating (and then changing) the setitem behavior. |
The
ser[5] = 5
case is an outlier because instead of having its label-vs-positional behavior determined byser.index._should_fallback_to_positional
, it is defermined byif is_integer(key) and not self.index.inferred_type == "integer":
The text was updated successfully, but these errors were encountered: