|
11 | 11 | from textwrap import dedent
|
12 | 12 | import typing
|
13 | 13 | from typing import (
|
| 14 | + TYPE_CHECKING, |
14 | 15 | Any,
|
15 | 16 | Callable,
|
16 | 17 | FrozenSet,
|
|
68 | 69 |
|
69 | 70 | from pandas.plotting import boxplot_frame_groupby
|
70 | 71 |
|
| 72 | +if TYPE_CHECKING: |
| 73 | + from pandas.core.internals import Block |
| 74 | + |
| 75 | + |
71 | 76 | NamedAgg = namedtuple("NamedAgg", ["column", "aggfunc"])
|
72 | 77 | # TODO(typing) the return value on this callable should be any *scalar*.
|
73 | 78 | AggScalar = Union[str, Callable[..., Any]]
|
@@ -987,11 +992,11 @@ def _iterate_slices(self) -> Iterable[Series]:
|
987 | 992 |
|
988 | 993 | def _cython_agg_general(
|
989 | 994 | self, how: str, alt=None, numeric_only: bool = True, min_count: int = -1
|
990 |
| - ): |
991 |
| - new_items, new_blocks = self._cython_agg_blocks( |
| 995 | + ) -> DataFrame: |
| 996 | + agg_items, agg_blocks = self._cython_agg_blocks( |
992 | 997 | how, alt=alt, numeric_only=numeric_only, min_count=min_count
|
993 | 998 | )
|
994 |
| - return self._wrap_agged_blocks(new_items, new_blocks) |
| 999 | + return self._wrap_agged_blocks(agg_blocks, items=agg_items) |
995 | 1000 |
|
996 | 1001 | def _cython_agg_blocks(
|
997 | 1002 | self, how: str, alt=None, numeric_only: bool = True, min_count: int = -1
|
@@ -1691,17 +1696,17 @@ def _wrap_transformed_output(
|
1691 | 1696 |
|
1692 | 1697 | return result
|
1693 | 1698 |
|
1694 |
| - def _wrap_agged_blocks(self, items, blocks): |
| 1699 | + def _wrap_agged_blocks(self, blocks: "Sequence[Block]", items: Index) -> DataFrame: |
1695 | 1700 | if not self.as_index:
|
1696 | 1701 | index = np.arange(blocks[0].values.shape[-1])
|
1697 |
| - mgr = BlockManager(blocks, [items, index]) |
| 1702 | + mgr = BlockManager(blocks, axes=[items, index]) |
1698 | 1703 | result = DataFrame(mgr)
|
1699 | 1704 |
|
1700 | 1705 | self._insert_inaxis_grouper_inplace(result)
|
1701 | 1706 | result = result._consolidate()
|
1702 | 1707 | else:
|
1703 | 1708 | index = self.grouper.result_index
|
1704 |
| - mgr = BlockManager(blocks, [items, index]) |
| 1709 | + mgr = BlockManager(blocks, axes=[items, index]) |
1705 | 1710 | result = DataFrame(mgr)
|
1706 | 1711 |
|
1707 | 1712 | if self.axis == 1:
|
@@ -1740,18 +1745,18 @@ def count(self):
|
1740 | 1745 | ids, _, ngroups = self.grouper.group_info
|
1741 | 1746 | mask = ids != -1
|
1742 | 1747 |
|
1743 |
| - val = ( |
| 1748 | + vals = ( |
1744 | 1749 | (mask & ~_isna_ndarraylike(np.atleast_2d(blk.get_values())))
|
1745 | 1750 | for blk in data.blocks
|
1746 | 1751 | )
|
1747 |
| - loc = (blk.mgr_locs for blk in data.blocks) |
| 1752 | + locs = (blk.mgr_locs for blk in data.blocks) |
1748 | 1753 |
|
1749 |
| - counted = [ |
1750 |
| - lib.count_level_2d(x, labels=ids, max_bin=ngroups, axis=1) for x in val |
1751 |
| - ] |
1752 |
| - blk = map(make_block, counted, loc) |
| 1754 | + counted = ( |
| 1755 | + lib.count_level_2d(x, labels=ids, max_bin=ngroups, axis=1) for x in vals |
| 1756 | + ) |
| 1757 | + blocks = [make_block(val, placement=loc) for val, loc in zip(counted, locs)] |
1753 | 1758 |
|
1754 |
| - return self._wrap_agged_blocks(data.items, list(blk)) |
| 1759 | + return self._wrap_agged_blocks(blocks, items=data.items) |
1755 | 1760 |
|
1756 | 1761 | def nunique(self, dropna: bool = True):
|
1757 | 1762 | """
|
|
0 commit comments