-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
REGR: fix eval with inplace=True to correctly update column values inplace #47550
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
Conversation
Hello @CloseChoice! Thanks for updating this PR. We checked the lines you've touched for PEP 8 issues, and found: There are currently no PEP 8 issues detected in this Pull Request. Cheers! 🍻 Comment last updated at 2022-08-19 08:09:31 UTC |
pandas/core/computation/eval.py
Outdated
and assigner in target.columns | ||
): | ||
loc = target.columns.get_loc(assigner) | ||
target._iset_item_mgr(loc, np.array(ret), inplace=inplace) |
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.
We should not use this here. Please use loc for this.
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.
Thanks, that helps a lot.
Could you add a whatsnew? Is there a suitable class for this test? The root cause was intended, so we have to fix them where they occur. |
Thanks for the answer. I added a whatsnew entry. |
pandas/core/computation/eval.py
Outdated
@@ -384,7 +384,10 @@ def eval( | |||
try: | |||
with warnings.catch_warnings(record=True): | |||
# TODO: Filter the warnings we actually care about here. | |||
target[assigner] = ret | |||
if hasattr(target, "loc"): |
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 not ideal. What could target be here? Dict, series, DataFrame, something else?
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.
Nope, basically these 3. Used ´isinstance(target, (DataFrame, Series))` instead
@CloseChoice I started converting the suggestion at #47449 (comment) into a PR, missing that you already opened one with a very similar fix! I hope you don't mind, but so I merged some of the changes I started doing in your PR:
|
Is it possible to get there with a MultiIndex? Similar to #47774 where the dimension reduction bothers us |
I am not sure if
If not using existing column names, but just assigning a new column, that still seems to work with this PR:
|
Thanks for checking |
@jorisvandenbossche I don't mind at all. Thanks for picking this up and improving upon it. |
Greenish, merging |
thx @CloseChoice |
This comment was marked as resolved.
This comment was marked as resolved.
…place (pandas-dev#47550) * fix pre-commit issues * fix linting errors * add inplace argument to isetitem and use in eval * changes due to PR discussions * fix issues * update eval * update whatsnew * add PR suggestions * update imports in eval.py * check inplace and use NDFrame + small update to test * update test to use using_copy_on_write * skip test for array manager Co-authored-by: Joris Van den Bossche <[email protected]>
…to correctly update column values inplace) (#48151) * REGR: fix eval with inplace=True to correctly update column values inplace (#47550) * fix pre-commit issues * fix linting errors * add inplace argument to isetitem and use in eval * changes due to PR discussions * fix issues * update eval * update whatsnew * add PR suggestions * update imports in eval.py * check inplace and use NDFrame + small update to test * update test to use using_copy_on_write * skip test for array manager Co-authored-by: Joris Van den Bossche <[email protected]> * Remove copy on write fixture Co-authored-by: Tobias Pitters <[email protected]> Co-authored-by: Joris Van den Bossche <[email protected]>
…place (pandas-dev#47550) * fix pre-commit issues * fix linting errors * add inplace argument to isetitem and use in eval * changes due to PR discussions * fix issues * update eval * update whatsnew * add PR suggestions * update imports in eval.py * check inplace and use NDFrame + small update to test * update test to use using_copy_on_write * skip test for array manager Co-authored-by: Joris Van den Bossche <[email protected]>
doc/source/whatsnew/vX.X.X.rst
file if fixing a bug or adding a new feature.The bad commit that causes this issue (see #43406) is the rootcause for multiple others, so am not sure if we want to tackle the overall problem bit by bit or if there is a generic solution to all of them.