-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
ENH: Add lazy copy for truncate #50477
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
@@ -66,12 +66,6 @@ def test_truncate(self, datetime_frame, frame_or_series): | |||
before=ts.index[-1] - ts.index.freq, after=ts.index[0] + ts.index.freq | |||
) | |||
|
|||
def test_truncate_copy(self, datetime_frame): |
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 now covered in the cow tests
if copy: | ||
result = result.copy() | ||
if copy or copy is None: | ||
result = result.copy(deep=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.
This might not be needed, since the result
is from an indexing operation, and already should be a lazy copy (when using a slice) with refs set up
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 could rewrite as if copy or copy is None and _using_copy_on_write()
, but we need the check for the non cow case
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 it be if copy or (copy is None and not _using_copy_on_write())
? (so with brackets and when not using CoW)
Essentially we need to same behaviour as this pattern that is used elsewhere, I think:
if copy is None:
if _using_copy_on_write():
copy = False
else:
copy = True
if copy:
result = result.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.
Ah yes, forgot the not
doc/source/whatsnew/vX.X.X.rst
file if fixing a bug or adding a new feature.