-
-
Notifications
You must be signed in to change notification settings - Fork 18.1k
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 warning mode: warn in case of chained assignment #55522
Changes from 12 commits
91551fa
1006fdd
d4832ac
bc1a455
1451bde
a051cec
b22e212
c61f0ea
fa4c50a
ebdad85
8e13e30
4bc0866
10229b9
db89e4a
7480219
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 |
---|---|---|
|
@@ -303,7 +303,7 @@ def test_constructor_dtype_nocast_view_dataframe( | |
assert df.values[0, 0] == 1 | ||
else: | ||
with tm.assert_cow_warning(warn_copy_on_write): | ||
should_be_view[0][0] = 99 | ||
should_be_view.iloc[0, 0] = 99 | ||
assert df.values[0, 0] == 99 | ||
|
||
def test_constructor_dtype_nocast_view_2d_array( | ||
|
@@ -312,8 +312,9 @@ def test_constructor_dtype_nocast_view_2d_array( | |
df = DataFrame([[1, 2], [3, 4]], dtype="int64") | ||
if not using_array_manager and not using_copy_on_write: | ||
should_be_view = DataFrame(df.values, dtype=df[0].dtype) | ||
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. Why should this warn? Not a blocking comment 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. I was thinking because currently it is a view and changes the parent dataframe? 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. No there is no way of knowing where the NumPy array came from, we have no clue that It was the backing array of a DataFrame before that 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. I assume that's something we will simply have to document in the list of breaking changes. |
||
with tm.assert_cow_warning(warn_copy_on_write): | ||
should_be_view[0][0] = 97 | ||
# TODO(CoW-warn) this should warn | ||
# with tm.assert_cow_warning(warn_copy_on_write): | ||
should_be_view.iloc[0, 0] = 97 | ||
assert df.values[0, 0] == 97 | ||
else: | ||
# INFO(ArrayManager) DataFrame(ndarray) doesn't necessarily preserve | ||
|
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.
Ẁe don't seem to have tests for where this would warn in the default mode (if you set a column here, like
df[slice]["col"] = ..
that already nevers update the original df, and you already get a (somewhat incorrect?, as you are not actually "setting on a copy", you are just not setting inplace) SettingWithCopyWarning.But to fabricate something that we should warn about in the default mode as well:
This updates the original
df
.So will have to update the above for that.
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.
I started on this locally, but given the many other open PRs that will give conficts, maybe I can leave finishing
DataFrame.__setitem__
proper warnings for default mode for a follow-up PR.