Skip to content

Commit 071bd27

Browse files
Backport PR pandas-dev#49908 on branch 1.5.x ( BUG: SeriesGroupBy.apply sets name attribute if result is DataFrame) (pandas-dev#49928)
Backport PR pandas-dev#49908: BUG: SeriesGroupBy.apply sets name attribute if result is DataFrame Co-authored-by: Marco Edward Gorelli <[email protected]>
1 parent 8dafe12 commit 071bd27

File tree

3 files changed

+4
-1
lines changed

3 files changed

+4
-1
lines changed

doc/source/whatsnew/v1.5.3.rst

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ Fixed regressions
1616
- Fixed performance regression in :meth:`Series.isin` when ``values`` is empty (:issue:`49839`)
1717
- Fixed regression in :meth:`DataFrameGroupBy.transform` when used with ``as_index=False`` (:issue:`49834`)
1818
- Enforced reversion of ``color`` as an alias for ``c`` and ``size`` as an alias for ``s`` in function :meth:`DataFrame.plot.scatter` (:issue:`49732`)
19+
- Fixed regression in :meth:`SeriesGroupBy.apply` setting a ``name`` attribute on the result if the result was a :class:`DataFrame` (:issue:`49907`)
1920
-
2021

2122
.. ---------------------------------------------------------------------------

pandas/core/groupby/generic.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -411,7 +411,8 @@ def _wrap_applied_output(
411411
not_indexed_same=not_indexed_same,
412412
override_group_keys=override_group_keys,
413413
)
414-
result.name = self.obj.name
414+
if isinstance(result, Series):
415+
result.name = self.obj.name
415416
return result
416417
else:
417418
# GH #6265 #24880

pandas/tests/groupby/test_apply.py

+1
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,7 @@ def f(piece):
335335
result = grouped.apply(f)
336336

337337
assert isinstance(result, DataFrame)
338+
assert not hasattr(result, "name") # GH49907
338339
tm.assert_index_equal(result.index, ts.index)
339340

340341

0 commit comments

Comments
 (0)