-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
REGR: __setitem__ with integer slices on Int/RangeIndex is broken (label instead of positional) #31469
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
I wonder if it's related to #31449 but I'm not using a multi-index. |
Thanks for the report. Seems this doesn't affect
will look into it |
you are label indexing with a slice with loc did this actually work previously? this should never have worked with .loc it might have with [] which has fallback integer indexing |
I do not remember any specific discussion about this, so I think it is definitely a regression. Slicing rows in |
@jreback if I've understood correctly, the issue is that everything is being set
|
maybe but indexing with an out or range label on both sides should return nothing so the results are correct |
ahh ok that is not correct; i would expect this indexer to return noting |
might be #31393 |
Asking for the shape, both in 0.25 and 1.0, you get
but assignment in version 1.0 assigns to everything. |
This is about positional indexing, so there is no "out of range label". The Again, I agree this is surprising behaviour. You would think it is label-based indexing, but it is not. I already described this 5 years in ago #9595. Some examples to illustrate this:
This those examples are for |
This is caused by #27383 I think (cc @jbrockmendel ), specifically: def _setitem_slice(self, key, value):
self._check_setitem_copy()
- self.loc._setitem_with_indexer(key, value)
+ self.loc[key] = value |
Thanks for investigating @jorisvandenbossche |
BTW, I think this is a rather serious regression, since it doesn't give an error, but rather silently modifies/corrupts your data, and thus can silently lead to wrong results. We should probably try to do a 1.0.1 quickly. |
Agreed. I won't be able to this weekend, but perhaps Monday? I'm hoping to fix up a bunch of the reported regressions today. |
I'll start a branch reverting the lines @jorisvandenbossche identified and open a PR after confirming that fixes this. After this is fixed for 1.0.1, we should discuss deprecating the surprising behavior. |
There's an backward incompatible change in pandas 1.0 that I didn't find in the changelog. I might have just overlooked it though.
In pandas 0.25.3 or lower, this results in the last four entries of X to be 1 and all the others zero. In pandas 1.0, it results in all entries of X being 1.
I assume it's a change of indexing axis 0 or axis 1?
The text was updated successfully, but these errors were encountered: