Apply grouped reduction function blockwise, returning a new BlockManager. Parameters ---------- func : grouped reduction function Returns ------- BlockManager
(self, func: Callable)
| 1643 | # Block-wise Operation |
| 1644 | |
| 1645 | def grouped_reduce(self, func: Callable) -> Self: |
| 1646 | """ |
| 1647 | Apply grouped reduction function blockwise, returning a new BlockManager. |
| 1648 | |
| 1649 | Parameters |
| 1650 | ---------- |
| 1651 | func : grouped reduction function |
| 1652 | |
| 1653 | Returns |
| 1654 | ------- |
| 1655 | BlockManager |
| 1656 | """ |
| 1657 | result_blocks: list[Block] = [] |
| 1658 | |
| 1659 | for blk in self.blocks: |
| 1660 | if blk.is_object: |
| 1661 | # split on object-dtype blocks bc some columns may raise |
| 1662 | # while others do not. |
| 1663 | for sb in blk._split(): |
| 1664 | applied = sb.apply(func) |
| 1665 | result_blocks = extend_blocks(applied, result_blocks) |
| 1666 | else: |
| 1667 | applied = blk.apply(func) |
| 1668 | result_blocks = extend_blocks(applied, result_blocks) |
| 1669 | |
| 1670 | if len(result_blocks) == 0: |
| 1671 | nrows = 0 |
| 1672 | else: |
| 1673 | nrows = result_blocks[0].values.shape[-1] |
| 1674 | index = default_index(nrows) |
| 1675 | |
| 1676 | # TODO shallow copy columns? |
| 1677 | return type(self).from_blocks(result_blocks, [self.axes[0].view(), index]) |
| 1678 | |
| 1679 | def reduce(self, func: Callable) -> Self: |
| 1680 | """ |
no test coverage detected