From 00db6ffbbe3472083998c44dc28e96117f64c617 Mon Sep 17 00:00:00 2001 From: jbrockmendel Date: Sun, 8 Sep 2019 16:46:10 -0700 Subject: [PATCH] CLN: raise ValueError instead of Exception --- pandas/core/groupby/generic.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/pandas/core/groupby/generic.py b/pandas/core/groupby/generic.py index e514162f84c37..e731cffea0671 100644 --- a/pandas/core/groupby/generic.py +++ b/pandas/core/groupby/generic.py @@ -324,7 +324,11 @@ def _aggregate_item_by_item(self, func, *args, **kwargs): if cast: result[item] = self._try_cast(result[item], data) - except ValueError: + except ValueError as err: + if "Must produce aggregated value" in str(err): + # raised in _aggregate_named, handle at higher level + # see test_apply_with_mutated_index + raise cannot_agg.append(item) continue except TypeError as e: @@ -1009,7 +1013,7 @@ def _aggregate_named(self, func, *args, **kwargs): group.name = name output = func(group, *args, **kwargs) if isinstance(output, (Series, Index, np.ndarray)): - raise Exception("Must produce aggregated value") + raise ValueError("Must produce aggregated value") result[name] = self._try_cast(output, group) return result