-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
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
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -56,7 +56,9 @@ def test_replace_categorical_series(to_replace, value, expected, flip_categories | |
("b", None, ["a", None], "Categorical.categories length are different"), | ||
], | ||
) | ||
def test_replace_categorical(to_replace, value, result, expected_error_msg): | ||
def test_replace_categorical( | ||
to_replace, value, result, expected_error_msg, using_copy_on_write | ||
): | ||
# GH#26988 | ||
cat = Categorical(["a", "b"]) | ||
expected = Categorical(result) | ||
|
@@ -68,7 +70,11 @@ def test_replace_categorical(to_replace, value, result, expected_error_msg): | |
# ensure non-inplace call does not affect original | ||
tm.assert_categorical_equal(cat, expected) | ||
|
||
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 commentThe 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:
which should then work the same for both CoW and not? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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.
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