-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
CoW: Add ChainedAssignmentError for replace with inplace=True #54023
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
CoW: Add ChainedAssignmentError for replace with inplace=True #54023
Conversation
pandas/core/generic.py
Outdated
@@ -7611,6 +7611,16 @@ def replace( | |||
) | |||
|
|||
inplace = validate_bool_kwarg(inplace, "inplace") | |||
if inplace: | |||
if not PYPY and using_copy_on_write(): | |||
refcount = 2 if PY311 else 3 |
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 can be updated now the other PR is merged
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.
Done
pd.Series(cat, copy=False).replace(to_replace, value, inplace=True) | ||
if using_copy_on_write: | ||
with tm.raises_chained_assignment_error(): | ||
pd.Series(cat, copy=False).replace(to_replace, value, inplace=True) | ||
else: | ||
pd.Series(cat, copy=False).replace(to_replace, value, inplace=True) | ||
tm.assert_categorical_equal(cat, expected) |
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.
In this case, I assume we are not necessarily testing that it is done on a single line, but just that the inplace works (and updates the underlying array. So I think it might be better to change the test to:
ser = pd.Series(cat, copy=False)
ser.replace(to_replace, value, inplace=True)
which should then work the same for both CoW and not?
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.
Don't care much either way, updated the test
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!
xref #48998
doc/source/whatsnew/vX.X.X.rst
file if fixing a bug or adding a new feature.