-
-
Notifications
You must be signed in to change notification settings - Fork 19.4k
DOC: clarify behavior of shallow copy with Copy-on-Write in NDFrame docstring #63291
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
base: main
Are you sure you want to change the base?
Conversation
rhshadrach
left a comment
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.
Looking good!
pandas/core/generic.py
Outdated
| the calling object's data or index (only references to the data | ||
| and index are copied). Any changes to the data of the original | ||
| will be reflected in the shallow copy (and vice versa). | ||
| and index are copied). With Copy-on-Write enabled by default, |
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.
Since CoW can't be disabled, I think we should remove the "enabled by default" bit.
| and index are copied). With Copy-on-Write enabled by default, | |
| and index are copied). With Copy-on-Write, |
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've removed the phase enabled by default
pandas/core/generic.py
Outdated
| changes to the data of the original will *not* be reflected in the | ||
| shallow copy (and vice versa). The shallow copy uses a lazy (deferred) |
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 true in terms of mutations at the e.g. Series level, but not array.
ser = pd.Series([1, 2, 3])
ser2 = ser.copy(deep=False)
ser.array[1] = 100
print(ser2)
# 0 1
# 1 100
# 2 3
# dtype: int64I'm not sure if we want to highlight this, cc @jorisvandenbossche
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.
Also not sure if we want to go into the details here, but in any case it would be good to slightly rephrase the "changes to the data of the original will not be reflected .." to "changes to the original will not be reflected .." (i.e. leave out the "the data of").
The above example currently also only works with .array, and not with eg .values (given the current state of #63099)
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'm actually done with the suggested changes! Please let me know if further improvement is needed...
closes #63289