Skip to content

Commit 3847b10

Browse files
jbrockmendelproost
authored andcommitted
CLN: raise ValueError instead of Exception (pandas-dev#28352)
1 parent 3778325 commit 3847b10

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

pandas/core/groupby/generic.py

+6-2
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,11 @@ def _aggregate_item_by_item(self, func, *args, **kwargs):
324324
if cast:
325325
result[item] = self._try_cast(result[item], data)
326326

327-
except ValueError:
327+
except ValueError as err:
328+
if "Must produce aggregated value" in str(err):
329+
# raised in _aggregate_named, handle at higher level
330+
# see test_apply_with_mutated_index
331+
raise
328332
cannot_agg.append(item)
329333
continue
330334
except TypeError as e:
@@ -1009,7 +1013,7 @@ def _aggregate_named(self, func, *args, **kwargs):
10091013
group.name = name
10101014
output = func(group, *args, **kwargs)
10111015
if isinstance(output, (Series, Index, np.ndarray)):
1012-
raise Exception("Must produce aggregated value")
1016+
raise ValueError("Must produce aggregated value")
10131017
result[name] = self._try_cast(output, group)
10141018

10151019
return result

0 commit comments

Comments
 (0)