Skip to content

PERF: copy blklocs/blknos in BlockManager.apply #43185

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
Aug 31, 2021
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
9 changes: 8 additions & 1 deletion pandas/core/internals/managers.py
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,8 @@ def apply(
if ignore_failures:
return self._combine(result_blocks)

return type(self).from_blocks(result_blocks, self.axes)
out = type(self).from_blocks(result_blocks, self.axes)
return out

def where(self: T, other, cond, align: bool, errors: str) -> T:
if align:
Expand Down Expand Up @@ -589,8 +590,14 @@ def copy_func(ax):
new_axes = list(self.axes)

res = self.apply("copy", deep=deep)

res.axes = new_axes

if self.ndim > 1:
# Avoid needing to re-compute these
res._blknos = self.blknos.copy()
res._blklocs = self.blklocs.copy()

if deep:
res._consolidate_inplace()
return res
Expand Down