diff --git a/pandas/core/groupby/generic.py b/pandas/core/groupby/generic.py index c766fcaa4f849..0ae3d71d077df 100644 --- a/pandas/core/groupby/generic.py +++ b/pandas/core/groupby/generic.py @@ -1074,15 +1074,8 @@ def _aggregate_frame(self, func, *args, **kwargs): else: for name in self.indices: data = self.get_group(name, obj=obj) - try: - fres = func(data, *args, **kwargs) - except AssertionError: - raise - except Exception: - wrapper = lambda x: func(x, *args, **kwargs) - result[name] = data.apply(wrapper, axis=axis) - else: - result[name] = self._try_cast(fres, data) + fres = func(data, *args, **kwargs) + result[name] = self._try_cast(fres, data) return self._wrap_frame_output(result, obj) diff --git a/pandas/tests/groupby/test_groupby.py b/pandas/tests/groupby/test_groupby.py index dff5baa9b5984..43e2a6f040414 100644 --- a/pandas/tests/groupby/test_groupby.py +++ b/pandas/tests/groupby/test_groupby.py @@ -775,7 +775,7 @@ def test_omit_nuisance(df): # won't work with axis = 1 grouped = df.groupby({"A": 0, "C": 0, "D": 1, "E": 1}, axis=1) - msg = r'\("unsupported operand type\(s\) for \+: ' "'Timestamp' and 'float'\", 0" + msg = r"unsupported operand type\(s\) for \+: 'Timestamp'" with pytest.raises(TypeError, match=msg): grouped.agg(lambda x: x.sum(0, numeric_only=False))