Skip to content

Commit 215ef6a

Browse files
authored
REF: avoid unnecessary raise in DataFrameGroupBy._cython_agg_general (#41265)
1 parent c61e66e commit 215ef6a

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

pandas/core/apply.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,10 @@ def agg_list_like(self) -> FrameOrSeriesUnion:
360360
# raised directly in _aggregate_named
361361
pass
362362
elif "no results" in str(err):
363-
# raised directly in _aggregate_multiple_funcs
363+
# reached in test_frame_apply.test_nuiscance_columns
364+
# where the colg.aggregate(arg) ends up going through
365+
# the selected_obj.ndim == 1 branch above with arg == ["sum"]
366+
# on a datetime64[ns] column
364367
pass
365368
else:
366369
raise

pandas/core/groupby/generic.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1110,6 +1110,7 @@ def _cython_agg_general(
11101110
# Note: we never get here with how="ohlc"; that goes through SeriesGroupBy
11111111

11121112
data: Manager2D = self._get_data_to_aggregate()
1113+
orig = data
11131114

11141115
if numeric_only:
11151116
data = data.get_numeric_data(copy=False)
@@ -1187,7 +1188,8 @@ def array_func(values: ArrayLike) -> ArrayLike:
11871188
# continue and exclude the block
11881189
new_mgr = data.grouped_reduce(array_func, ignore_failures=True)
11891190

1190-
if not len(new_mgr):
1191+
if not len(new_mgr) and len(orig):
1192+
# If the original Manager was already empty, no need to raise
11911193
raise DataError("No numeric types to aggregate")
11921194

11931195
return self._wrap_agged_manager(new_mgr)

0 commit comments

Comments
 (0)