-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
REGR: Fix inplace updates on column to set correct values #35936
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
REGR: Fix inplace updates on column to set correct values #35936
Conversation
LGTM pending green I'd also be OK with chasing the unwrapping up the call chain to unwrap earlier |
pandas/core/internals/managers.py
Outdated
@@ -1027,6 +1027,8 @@ def iset(self, loc: Union[int, slice, np.ndarray], value): | |||
Set new item in-place. Does not consolidate. Adds new Block if not | |||
contained in the current set of items | |||
""" | |||
if isinstance(value, ABCSeries): | |||
value = value._values |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
extract_array to handle Index too?
pandas/core/internals/managers.py
Outdated
@@ -1027,6 +1027,8 @@ def iset(self, loc: Union[int, slice, np.ndarray], value): | |||
Set new item in-place. Does not consolidate. Adds new Block if not | |||
contained in the current set of items | |||
""" | |||
if isinstance(value, ABCSeries): | |||
value = value._values |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jbrockmendel I suppose ideally we ensure that iset
always already gets the correct values, so never a Series. And so I could also unpack (or maybe use extract_array
?) where iset
is called in this case:
Lines 3273 to 3278 in a1f6056
def _maybe_cache_changed(self, item, value) -> None: | |
""" | |
The object has called back to us saying maybe it has changed. | |
""" | |
loc = self._info_axis.get_loc(item) | |
self._mgr.iset(loc, value) |
But: 1) I am not fully sure in which case this _maybe_cache_changed
is used, and so value
can also be something else as a Series (so DataFrame)? and 2) iset
is being used in other places as well, where the same issue might occur
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
re 2: I think iset is only called from 2 places in NDFrame. shouldnt be that hard to check unwrapping there, annotate iset
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, iset
itself is indeed only additionally used in _iset_item
, but that is then used in _set_item
and in indexing code, ... (and checking in the indexing code what values can be passed is already a bit less trivial ;-))
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK. I might do a follow-up to try to push the check earlier
def test_fillna_fill_other(self, data): | ||
# inplace update doesn't work correctly with patched extension arrays | ||
# extract_array returns PandasArray, while dtype is a numpy dtype | ||
super().test_fillna_fill_other(data_missing) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a bit strange, but because I switched if isinstance(.., Series): value = value._value
to extract_array
, this test started to fail. That is because for test_numpy.py
we patch the PandasArray to not be special cased, and then extract_array
returns a PandasArray, even for a numpy dtype. And thus, in iset
we set a PandasArray into a consolidated numpy block ..
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yah im not a fan of this patching, OK with xfailing
thanks @jorisvandenbossche |
@meeseeksdev backport 1.1.x |
Owee, I'm MrMeeseeks, Look at me. There seem to be a conflict, please backport manually. Here are approximate instructions:
And apply the correct labels and milestones. Congratulation you did some good work ! Hopefully your backport PR will be tested by the continuous integration and merged soon! If these instruction are inaccurate, feel free to suggest an improvement. |
… set correct values)
…ct values) (#36009) Co-authored-by: Joris Van den Bossche <[email protected]>
Closes #35731