diff --git a/pandas/core/apply.py b/pandas/core/apply.py index 1aa08356982d2..693b1832ed3c9 100644 --- a/pandas/core/apply.py +++ b/pandas/core/apply.py @@ -360,7 +360,10 @@ def agg_list_like(self) -> FrameOrSeriesUnion: # raised directly in _aggregate_named pass elif "no results" in str(err): - # raised directly in _aggregate_multiple_funcs + # reached in test_frame_apply.test_nuiscance_columns + # where the colg.aggregate(arg) ends up going through + # the selected_obj.ndim == 1 branch above with arg == ["sum"] + # on a datetime64[ns] column pass else: raise diff --git a/pandas/core/groupby/generic.py b/pandas/core/groupby/generic.py index fd4b0cfa87950..27e07deb69e9c 100644 --- a/pandas/core/groupby/generic.py +++ b/pandas/core/groupby/generic.py @@ -1110,6 +1110,7 @@ def _cython_agg_general( # Note: we never get here with how="ohlc"; that goes through SeriesGroupBy data: Manager2D = self._get_data_to_aggregate() + orig = data if numeric_only: data = data.get_numeric_data(copy=False) @@ -1187,7 +1188,8 @@ def array_func(values: ArrayLike) -> ArrayLike: # continue and exclude the block new_mgr = data.grouped_reduce(array_func, ignore_failures=True) - if not len(new_mgr): + if not len(new_mgr) and len(orig): + # If the original Manager was already empty, no need to raise raise DataError("No numeric types to aggregate") return self._wrap_agged_manager(new_mgr)