Skip to content

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

Merged
merged 4 commits into from
Jan 4, 2023
Merged

Conversation

phofl
Copy link
Member

@phofl phofl commented Dec 28, 2022

@@ -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):
Copy link
Member Author

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)
Copy link
Member

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

Copy link
Member Author

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

Copy link
Member

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()

Copy link
Member Author

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

@jorisvandenbossche jorisvandenbossche merged commit 45bd637 into pandas-dev:main Jan 4, 2023
@phofl phofl deleted the cow_truncate branch January 4, 2023 09:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants