Skip to content

REF: de-duplicate CoW helpers #53899

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 1 commit into from
Jun 28, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 2 additions & 17 deletions pandas/core/internals/blocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -583,20 +583,6 @@ def _maybe_copy(self, using_cow: bool, inplace: bool) -> Self:
blk = self if inplace else self.copy()
return blk

@final
def _get_values_and_refs(self, using_cow, inplace):
if using_cow:
if inplace and not self.refs.has_reference():
refs = self.refs
new_values = self.values
else:
refs = None
new_values = self.values.copy()
else:
refs = None
new_values = self.values if inplace else self.values.copy()
return new_values, refs

@final
def _get_refs_and_copy(self, using_cow: bool, inplace: bool):
refs = None
Expand Down Expand Up @@ -738,11 +724,10 @@ def _replace_regex(

rx = re.compile(to_replace)

new_values, refs = self._get_values_and_refs(using_cow, inplace)
block = self._maybe_copy(using_cow, inplace)

replace_regex(new_values, rx, value, mask)
replace_regex(block.values, rx, value, mask)

block = self.make_block(new_values, refs=refs)
return block.convert(copy=False, using_cow=using_cow)

@final
Expand Down