Skip to content

TST: Copy on Write for filter #50589

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 3 commits into from
Jan 6, 2023
Merged

Conversation

lithomas1
Copy link
Member

df_orig = df.copy()
df2 = df.filter(**filter_kwargs)
if using_copy_on_write:
assert np.shares_memory(get_array(df2, "a"), get_array(df, "a"))

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Out of curiosity, do you think that numpy.may_share_memory() function can be faster than using np.shares_memory()? I compared it once, and it seems like it could be the case, but not super important.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't really matter for tests, but seems like it could be faster


# mutating df2 triggers a copy-on-write for that column/block
if using_copy_on_write:
df2.iloc[0, 0] = 0
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 was raising a SettingWithCopy error(reasonable, since filter uses loc) so I just moved it inside the 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.

Yeah had the same problem somewhere else

@lithomas1 lithomas1 marked this pull request as ready for review January 5, 2023 22:13
@phofl phofl added this to the 2.0 milestone Jan 6, 2023
@phofl phofl merged commit 4520f84 into pandas-dev:main Jan 6, 2023
@phofl
Copy link
Member

phofl commented Jan 6, 2023

thx @lithomas1

@lithomas1 lithomas1 deleted the test-filter-cow branch January 6, 2023 21:47
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.

3 participants