| 1763 | |
| 1764 | @final |
| 1765 | def _cython_agg_general( |
| 1766 | self, |
| 1767 | how: str, |
| 1768 | alt: Callable | None = None, |
| 1769 | numeric_only: bool = False, |
| 1770 | min_count: int = -1, |
| 1771 | **kwargs, |
| 1772 | ): |
| 1773 | # Note: we never get here with how="ohlc" for DataFrameGroupBy; |
| 1774 | # that goes through SeriesGroupBy |
| 1775 | |
| 1776 | if not is_bool(numeric_only): |
| 1777 | raise ValueError("numeric_only accepts only Boolean values") |
| 1778 | |
| 1779 | data = self._get_data_to_aggregate(numeric_only=numeric_only, name=how) |
| 1780 | |
| 1781 | def array_func(values: ArrayLike) -> ArrayLike: |
| 1782 | try: |
| 1783 | result = self._grouper._cython_operation( |
| 1784 | "aggregate", |
| 1785 | values, |
| 1786 | how, |
| 1787 | axis=data.ndim - 1, |
| 1788 | min_count=min_count, |
| 1789 | **kwargs, |
| 1790 | ) |
| 1791 | except NotImplementedError: |
| 1792 | # generally if we have numeric_only=False |
| 1793 | # and non-applicable functions |
| 1794 | # try to python agg |
| 1795 | # TODO: shouldn't min_count matter? |
| 1796 | # TODO: avoid special casing SparseArray here |
| 1797 | if how in ["any", "all"] and isinstance(values, SparseArray): |
| 1798 | pass |
| 1799 | elif alt is None or how in ["any", "all", "std", "sem"]: |
| 1800 | raise # TODO: re-raise as TypeError? should not be reached |
| 1801 | else: |
| 1802 | return result |
| 1803 | |
| 1804 | assert alt is not None |
| 1805 | result = self._agg_py_fallback(how, values, ndim=data.ndim, alt=alt) |
| 1806 | return result |
| 1807 | |
| 1808 | new_mgr = data.grouped_reduce(array_func) |
| 1809 | res = self._wrap_agged_manager(new_mgr) |
| 1810 | if how in ["idxmin", "idxmax"]: |
| 1811 | # mypy expects how to be Literal["idxmin", "idxmax"]. |
| 1812 | res = self._wrap_idxmax_idxmin(res, how=how, skipna=kwargs["skipna"]) # type: ignore[arg-type] |
| 1813 | out = self._wrap_aggregated_output(res) |
| 1814 | return out |
| 1815 | |
| 1816 | def _cython_transform(self, how: str, numeric_only: bool = False, **kwargs): |
| 1817 | raise AbstractMethodError(self) |