-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
API/CoW: Return copies for head and tail #54011
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 3 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 |
---|---|---|
|
@@ -895,16 +895,17 @@ def test_head_tail(method, using_copy_on_write): | |
df2._mgr._verify_integrity() | ||
|
||
if using_copy_on_write: | ||
assert np.shares_memory(get_array(df2, "a"), get_array(df, "a")) | ||
assert np.shares_memory(get_array(df2, "b"), get_array(df, "b")) | ||
assert not np.shares_memory(get_array(df2, "a"), get_array(df, "a")) | ||
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. Can you add a comment here to note we explicitly deviate in head/tail methods to do an eager copy (as it now contrasts with most other tests in this file) 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. Makes sense |
||
assert not np.shares_memory(get_array(df2, "b"), get_array(df, "b")) | ||
|
||
# modify df2 to trigger CoW for that block | ||
df2.iloc[0, 0] = 0 | ||
assert np.shares_memory(get_array(df2, "b"), get_array(df, "b")) | ||
if using_copy_on_write: | ||
assert not np.shares_memory(get_array(df2, "b"), get_array(df, "b")) | ||
assert not np.shares_memory(get_array(df2, "a"), get_array(df, "a")) | ||
else: | ||
# without CoW enabled, head and tail return views. Mutating df2 also mutates df. | ||
assert np.shares_memory(get_array(df2, "b"), get_array(df, "b")) | ||
df2.iloc[0, 0] = 1 | ||
tm.assert_frame_equal(df, df_orig) | ||
|
||
|
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.
Should we clarify this as "deep copy"? With CoW, the methods already do return an object that behaves as a copy / is a shallow copy.
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.
Makes sense, thx