diff --git a/pandas/core/groupby/generic.py b/pandas/core/groupby/generic.py index 8191c3519a36af..a78857423e7e0a 100644 --- a/pandas/core/groupby/generic.py +++ b/pandas/core/groupby/generic.py @@ -1067,14 +1067,9 @@ def _aggregate_frame(self, func, *args, **kwargs): result = OrderedDict() if axis != obj._info_axis_number: - try: - for name, data in self: - fres = func(data, *args, **kwargs) - result[name] = self._try_cast(fres, data) - except AssertionError: - raise - except Exception: - return self._aggregate_item_by_item(func, *args, **kwargs) + for name, data in self: + fres = func(data, *args, **kwargs) + result[name] = self._try_cast(fres, data) else: for name in self.indices: data = self.get_group(name, obj=obj) @@ -1441,6 +1436,7 @@ def _choose_path(self, fast_path, slow_path, group): raise except Exception: # Hard to know ex-ante what exceptions `fast_path` might raise + # TODO: no test cases get here return path, res # verify fast path does not change columns (and names), otherwise diff --git a/pandas/core/groupby/ops.py b/pandas/core/groupby/ops.py index e380cf5930f97d..fcc646dec89d9b 100644 --- a/pandas/core/groupby/ops.py +++ b/pandas/core/groupby/ops.py @@ -655,7 +655,15 @@ def agg_series(self, obj, func): return self._aggregate_series_fast(obj, func) except AssertionError: raise - except Exception: + except ValueError as err: + if "No result." in str(err): + # raised in libreduction + pass + elif "Function does not reduce" in str(err): + # raised in libreduction + pass + else: + raise return self._aggregate_series_pure_python(obj, func) def _aggregate_series_fast(self, obj, func): diff --git a/pandas/core/series.py b/pandas/core/series.py index 1039e9af929d48..ea48b3603623ac 100644 --- a/pandas/core/series.py +++ b/pandas/core/series.py @@ -1288,6 +1288,7 @@ def _set_with(self, key, value): else: if isinstance(key, tuple): try: + # TODO: no test cases that get here self._set_values(key, value) except Exception: pass