|
15 | 15 | from functools import partial
|
16 | 16 | from textwrap import dedent
|
17 | 17 | from typing import (
|
18 |
| - TYPE_CHECKING, |
19 | 18 | Any,
|
20 | 19 | Callable,
|
21 | 20 | Dict,
|
|
25 | 24 | List,
|
26 | 25 | Mapping,
|
27 | 26 | Optional,
|
28 |
| - Sequence, |
29 | 27 | Type,
|
30 | 28 | TypeVar,
|
31 | 29 | Union,
|
|
115 | 113 |
|
116 | 114 | from pandas.plotting import boxplot_frame_groupby
|
117 | 115 |
|
118 |
| -if TYPE_CHECKING: |
119 |
| - from pandas.core.internals import Block |
120 |
| - |
121 |
| - |
122 | 116 | NamedAgg = namedtuple("NamedAgg", ["column", "aggfunc"])
|
123 | 117 | # TODO(typing) the return value on this callable should be any *scalar*.
|
124 | 118 | AggScalar = Union[str, Callable[..., Any]]
|
@@ -1083,7 +1077,7 @@ def _cython_agg_general(
|
1083 | 1077 | agg_mgr = self._cython_agg_blocks(
|
1084 | 1078 | how, alt=alt, numeric_only=numeric_only, min_count=min_count
|
1085 | 1079 | )
|
1086 |
| - return self._wrap_agged_blocks(agg_mgr.blocks, items=agg_mgr.items) |
| 1080 | + return self._wrap_agged_manager(agg_mgr) |
1087 | 1081 |
|
1088 | 1082 | def _cython_agg_blocks(
|
1089 | 1083 | self, how: str, alt=None, numeric_only: bool = True, min_count: int = -1
|
@@ -1183,7 +1177,7 @@ def blk_func(bvalues: ArrayLike) -> ArrayLike:
|
1183 | 1177 | # TypeError -> we may have an exception in trying to aggregate
|
1184 | 1178 | # continue and exclude the block
|
1185 | 1179 | # NotImplementedError -> "ohlc" with wrong dtype
|
1186 |
| - new_mgr = data.apply(blk_func, ignore_failures=True) |
| 1180 | + new_mgr = data.grouped_reduce(blk_func, ignore_failures=True) |
1187 | 1181 |
|
1188 | 1182 | if not len(new_mgr):
|
1189 | 1183 | raise DataError("No numeric types to aggregate")
|
@@ -1761,17 +1755,17 @@ def _wrap_transformed_output(
|
1761 | 1755 |
|
1762 | 1756 | return result
|
1763 | 1757 |
|
1764 |
| - def _wrap_agged_blocks(self, blocks: Sequence[Block], items: Index) -> DataFrame: |
| 1758 | + def _wrap_agged_manager(self, mgr: BlockManager) -> DataFrame: |
1765 | 1759 | if not self.as_index:
|
1766 |
| - index = np.arange(blocks[0].values.shape[-1]) |
1767 |
| - mgr = BlockManager(blocks, axes=[items, index]) |
| 1760 | + index = np.arange(mgr.shape[1]) |
| 1761 | + mgr.axes[1] = ibase.Index(index) |
1768 | 1762 | result = self.obj._constructor(mgr)
|
1769 | 1763 |
|
1770 | 1764 | self._insert_inaxis_grouper_inplace(result)
|
1771 | 1765 | result = result._consolidate()
|
1772 | 1766 | else:
|
1773 | 1767 | index = self.grouper.result_index
|
1774 |
| - mgr = BlockManager(blocks, axes=[items, index]) |
| 1768 | + mgr.axes[1] = index |
1775 | 1769 | result = self.obj._constructor(mgr)
|
1776 | 1770 |
|
1777 | 1771 | if self.axis == 1:
|
@@ -1821,13 +1815,13 @@ def hfunc(bvalues: ArrayLike) -> ArrayLike:
|
1821 | 1815 | counted = lib.count_level_2d(masked, labels=ids, max_bin=ngroups, axis=1)
|
1822 | 1816 | return counted
|
1823 | 1817 |
|
1824 |
| - new_mgr = data.apply(hfunc) |
| 1818 | + new_mgr = data.grouped_reduce(hfunc) |
1825 | 1819 |
|
1826 | 1820 | # If we are grouping on categoricals we want unobserved categories to
|
1827 | 1821 | # return zero, rather than the default of NaN which the reindexing in
|
1828 |
| - # _wrap_agged_blocks() returns. GH 35028 |
| 1822 | + # _wrap_agged_manager() returns. GH 35028 |
1829 | 1823 | with com.temp_setattr(self, "observed", True):
|
1830 |
| - result = self._wrap_agged_blocks(new_mgr.blocks, items=data.items) |
| 1824 | + result = self._wrap_agged_manager(new_mgr) |
1831 | 1825 |
|
1832 | 1826 | return self._reindex_output(result, fill_value=0)
|
1833 | 1827 |
|
|
0 commit comments