Skip to content

Commit 1d1904f

Browse files
author
Marco Gorelli
committed
wip
1 parent 761bceb commit 1d1904f

File tree

3 files changed

+6
-3
lines changed

3 files changed

+6
-3
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-
18+
- bug ``Groupby.apply`` was returning ``TypeError`` if called with TypeError if called with `lambda x: x.index.to_list()` (:issue:`31441`)
1919

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

pandas/_libs/reduction.pyx

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from copy import copy
1+
from copy import copy, deepcopy
22
from distutils.version import LooseVersion
33

44
from cython import Py_ssize_t
@@ -499,7 +499,9 @@ 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 not is_scalar(piece):
502+
if isinstance(piece, list):
503+
piece = deepcopy(piece)
504+
elif not is_scalar(piece):
503505
# Need to copy data to avoid appending references
504506
if hasattr(piece, "copy"):
505507
piece = piece.copy(deep="all")

pandas/tests/extension/conftest.py

+1
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ def box_in_series(request):
126126
lambda x: [1] * len(x),
127127
lambda x: Series([1] * len(x)),
128128
lambda x: x,
129+
lambda x: x.index.to_list()
129130
],
130131
ids=["scalar", "list", "series", "object"],
131132
)

0 commit comments

Comments
 (0)