MCPcopy
hub / github.com/pandas-dev/pandas / grouped_reduce

Method grouped_reduce

pandas/core/internals/managers.py:1645–1677  ·  view source on GitHub ↗

Apply grouped reduction function blockwise, returning a new BlockManager. Parameters ---------- func : grouped reduction function Returns ------- BlockManager

(self, func: Callable)

Source from the content-addressed store, hash-verified

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 """

Callers 3

_cython_agg_generalMethod · 0.45
countMethod · 0.45
quantileMethod · 0.45

Calls 6

extend_blocksFunction · 0.90
default_indexFunction · 0.90
_splitMethod · 0.80
applyMethod · 0.45
from_blocksMethod · 0.45
viewMethod · 0.45

Tested by

no test coverage detected