Skip to content

Commit ef2ebf3

Browse files
committed
Make reduce return single block
1 parent 9f76217 commit ef2ebf3

File tree

2 files changed

+3
-8
lines changed

2 files changed

+3
-8
lines changed

pandas/core/internals/blocks.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,7 @@ def apply(self, func, **kwargs) -> list[Block]:
350350
return self._split_op_result(result)
351351

352352
@final
353-
def reduce(self, func) -> list[Block]:
353+
def reduce(self, func) -> Block:
354354
# We will apply the function and reshape the result into a single-row
355355
# Block with the same mgr_locs; squeezing will be done at a higher level
356356
assert self.ndim == 2
@@ -362,8 +362,7 @@ def reduce(self, func) -> list[Block]:
362362
else:
363363
res_values = result.reshape(-1, 1)
364364

365-
nb = self.make_block(res_values)
366-
return [nb]
365+
return self.make_block(res_values)
367366

368367
@final
369368
def _split_op_result(self, result: ArrayLike) -> list[Block]:

pandas/core/internals/managers.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1651,11 +1651,7 @@ def reduce(self, func: Callable) -> Self:
16511651
# If 2D, we assume that we're operating column-wise
16521652
assert self.ndim == 2
16531653

1654-
res_blocks: list[Block] = []
1655-
for blk in self.blocks:
1656-
nbs = blk.reduce(func)
1657-
res_blocks.extend(nbs)
1658-
1654+
res_blocks = [blk.reduce(func) for blk in self.blocks]
16591655
index = default_index(1) # placeholder
16601656
new_mgr = type(self).from_blocks(res_blocks, [self.items, index])
16611657
return new_mgr

0 commit comments

Comments
 (0)