Skip to content

Commit 6369f76

Browse files
author
Marco Gorelli
committed
change fix according to review
1 parent e3ab3a5 commit 6369f76

File tree

3 files changed

+4
-5
lines changed

3 files changed

+4
-5
lines changed

doc/source/whatsnew/v1.0.1.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ including other versions of pandas.
1515

1616
Bug fixes
1717
~~~~~~~~~
18-
- bug ``Groupby.apply`` was returning ``TypeError`` if called with function which returned list (:issue:`31441`)
18+
- Bug in :meth:`GroupBy.apply` was raising ``TypeError`` if called with function which returned list (:issue:`31441`)
1919

2020
Categorical
2121
^^^^^^^^^^^

pandas/_libs/reduction.pyx

+2-4
Original file line numberDiff line numberDiff line change
@@ -499,12 +499,10 @@ def apply_frame_axis0(object frame, object f, object names,
499499
# `piece` might not have an index, could be e.g. an int
500500
pass
501501

502-
if isinstance(piece, list):
503-
piece = deepcopy(piece)
504-
elif not is_scalar(piece):
502+
if not is_scalar(piece):
505503
# Need to copy data to avoid appending references
506504
if hasattr(piece, "copy"):
507-
piece = piece.copy(deep="all")
505+
piece = deepcopy(piece)
508506
else:
509507
piece = copy(piece)
510508

pandas/tests/groupby/test_apply.py

+1
Original file line numberDiff line numberDiff line change
@@ -830,6 +830,7 @@ def test_apply_index_has_complex_internals(index):
830830

831831

832832
def test_apply_function_returns_list():
833+
# GH 31441
833834
df = pd.DataFrame(["A", "A", "B", "B"], columns=["groups"])
834835
result = df.groupby("groups").apply(lambda x: x.index.to_list())
835836
expected = pd.Series([[0, 1], [2, 3]], index=pd.Index(["A", "B"], name="groups"))

0 commit comments

Comments
 (0)