-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
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
Conversation
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.
Thanks!
Would there be a usecase for adding a keyword to let you not make the eager copy? That would probably only be useful if you would use head/tail for non-exploration cases, in which case you can use iloc instead (although people might prefer a method in case of method chaining)
doc/source/whatsnew/v2.1.0.rst
Outdated
@@ -25,6 +25,7 @@ Copy-on-Write improvements | |||
- The :class:`DataFrame` constructor, when constructing a DataFrame from a dictionary | |||
of Index objects and specifying ``copy=False``, will now use a lazy copy | |||
of those Index objects for the columns of the DataFrame (:issue:`52947`) | |||
- :meth:`DataFrame.head` and :meth:`DataFrame.tail` will now return copies (:issue:`54011`) |
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
@@ -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 comment
The 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 comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense
I would not add a keyword, I am not convinced that there is a proper use-case that would require such a keyword |
doc/source/whatsnew/vX.X.X.rst
file if fixing a bug or adding a new feature.this is something we talked about to avoid messing up references in Jupyter environments (xref #48998)