Skip to content
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

ENH: Optimize replace to avoid copying when not necessary #50918

Merged
merged 17 commits into from
Feb 26, 2023

Conversation

phofl
Copy link
Member

@phofl phofl commented Jan 21, 2023

  • closes #xxxx (Replace xxxx with the GitHub issue number)
  • Tests added and passed if fixing a bug or adding a new feature
  • All code checks passed.
  • Added type annotations to new arguments/methods/functions.
  • Added an entry in the latest doc/source/whatsnew/vX.X.X.rst file if fixing a bug or adding a new feature.

@lithomas1
Copy link
Member

Does this fix any of the existing cases in test_replace?

@phofl
Copy link
Member Author

phofl commented Jan 26, 2023

No, not yet

pandas/core/internals/blocks.py Outdated Show resolved Hide resolved
pandas/core/internals/blocks.py Outdated Show resolved Hide resolved
if using_cow:
return [self.copy(deep=False)]
else:
return [self] if inplace else [self.copy()]

if mask is None:
mask = missing.mask_missing(values, to_replace)
if not mask.any():
Copy link
Member

Choose a reason for hiding this comment

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

If we pass an axis(I thinkaxis=0 should work, need to be careful of 1-D values/mask though), than we should have enough info to split the block.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yep agree, but right now this is not that high on my list of priorities. With the ref tracking how it is right now, this only defers the copy a little bit

Copy link
Member

@lithomas1 lithomas1 left a comment

Choose a reason for hiding this comment

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

LGTM. Can you update the list on #49473?

@lithomas1 lithomas1 added this to the 2.0 milestone Feb 26, 2023
@lithomas1 lithomas1 merged commit 1130360 into pandas-dev:main Feb 26, 2023
@lithomas1
Copy link
Member

thanks @phofl

@phofl phofl deleted the cow_replace branch February 26, 2023 20:19
phofl added a commit that referenced this pull request Feb 26, 2023
…pying when not necessary) (#51652)

Backport PR #50918: ENH: Optimize replace to avoid copying when not necessary

Co-authored-by: Patrick Hoefler <61934744+phofl@users.noreply.github.com>
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