Skip to content

Commit 9af0ad3

Browse files
jbrockmendelfeefladder
authored andcommitted
PERF: copy blklocs/blknos in BlockManager.apply (pandas-dev#43185)
1 parent d6bfc03 commit 9af0ad3

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

pandas/core/internals/managers.py

+8-1
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,8 @@ def apply(
330330
if ignore_failures:
331331
return self._combine(result_blocks)
332332

333-
return type(self).from_blocks(result_blocks, self.axes)
333+
out = type(self).from_blocks(result_blocks, self.axes)
334+
return out
334335

335336
def where(self: T, other, cond, align: bool, errors: str) -> T:
336337
if align:
@@ -595,8 +596,14 @@ def copy_func(ax):
595596
new_axes = list(self.axes)
596597

597598
res = self.apply("copy", deep=deep)
599+
598600
res.axes = new_axes
599601

602+
if self.ndim > 1:
603+
# Avoid needing to re-compute these
604+
res._blknos = self.blknos.copy()
605+
res._blklocs = self.blklocs.copy()
606+
600607
if deep:
601608
res._consolidate_inplace()
602609
return res

0 commit comments

Comments
 (0)