diff --git a/doc/source/whatsnew/v1.5.3.rst b/doc/source/whatsnew/v1.5.3.rst index e7428956c50b5..e0bcd81805cc1 100644 --- a/doc/source/whatsnew/v1.5.3.rst +++ b/doc/source/whatsnew/v1.5.3.rst @@ -16,6 +16,7 @@ Fixed regressions - Fixed performance regression in :meth:`Series.isin` when ``values`` is empty (:issue:`49839`) - Fixed regression in :meth:`DataFrameGroupBy.transform` when used with ``as_index=False`` (:issue:`49834`) - Enforced reversion of ``color`` as an alias for ``c`` and ``size`` as an alias for ``s`` in function :meth:`DataFrame.plot.scatter` (:issue:`49732`) +- Fixed regression in :meth:`SeriesGroupBy.apply` setting a ``name`` attribute on the result if the result was a :class:`DataFrame` (:issue:`49907`) - .. --------------------------------------------------------------------------- diff --git a/pandas/core/groupby/generic.py b/pandas/core/groupby/generic.py index 97d332394e045..7e6e138fa8fe6 100644 --- a/pandas/core/groupby/generic.py +++ b/pandas/core/groupby/generic.py @@ -411,7 +411,8 @@ def _wrap_applied_output( not_indexed_same=not_indexed_same, override_group_keys=override_group_keys, ) - result.name = self.obj.name + if isinstance(result, Series): + result.name = self.obj.name return result else: # GH #6265 #24880 diff --git a/pandas/tests/groupby/test_apply.py b/pandas/tests/groupby/test_apply.py index 47ea6a99ffea9..dfd62394c840e 100644 --- a/pandas/tests/groupby/test_apply.py +++ b/pandas/tests/groupby/test_apply.py @@ -335,6 +335,7 @@ def f(piece): result = grouped.apply(f) assert isinstance(result, DataFrame) + assert not hasattr(result, "name") # GH49907 tm.assert_index_equal(result.index, ts.index)