-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
CoW warning mode: setting values into single column of DataFrame #56020
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: setting values into single column of DataFrame #56020
Conversation
Green! |
if not using_cow: | ||
# Normally would need to do this before, but | ||
# numpy only returns same array when round operation | ||
# is no-op | ||
# https://github.com/numpy/numpy/blob/486878b37fc7439a3b2b87747f50db9b62fea8eb/numpy/core/src/multiarray/calculation.c#L625-L636 | ||
values = values.copy() | ||
else: | ||
refs = self.refs |
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 were incorrectly adding forwarding refs always, even when we did make a copy. For CoW this doesn't cause anything wrong, but for the warning mode this gave false positive warnings.
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 sorry for that, I didn't care much about non CoW when adding all of those
df = DataFrame({"a": [1, 2, 3], "b": 1, "c": 1}) | ||
view = df[:] | ||
|
||
df["b"] = 100 | ||
arr = get_array(df, "a") | ||
view = None # noqa: F841 | ||
df.iloc[0, 0] = 100 | ||
# TODO(CoW-warn) false positive? |
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, comment explaining this is 3 lines below
Next subtask of #56019.
This tackles
mgr.column_setitem
, which is used to set values into a single column (but not setting the full column, so likedf.loc[idx, "col"] = ..
)