Skip to content

Commit d47d34d

Browse files
idor980Ido Ronen
authored and
Yi Wei
committed
Add test case for applying a function to a groupby object that append… (pandas-dev#53138)
* Add test case for applying a function to a groupby object that appends each group to a list without using copy() function. The test checks if the groups are correctly appended to the list. This resolves GH issue 17718. * installed pre-commit * update expected_value * update expected and installed pre-commit * test commit * committing update for expected value from my last verified commit * update expected_value to pd.DataFrame({index: [0] * 10, 0: [1] * 10}, index=pd.RangeIndex(0, 100, step=10)) --------- Co-authored-by: Ido Ronen <[email protected]>
1 parent 9da8b92 commit d47d34d

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

pandas/tests/groupby/test_apply.py

+17
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,23 @@
1919
from pandas.tests.groupby import get_groupby_method_args
2020

2121

22+
def test_apply_func_that_appends_group_to_list_without_copy():
23+
# GH: 17718
24+
25+
df = DataFrame(1, index=list(range(10)) * 10, columns=[0]).reset_index()
26+
groups = []
27+
28+
def store(group):
29+
groups.append(group)
30+
31+
df.groupby("index").apply(store)
32+
expected_value = DataFrame(
33+
{"index": [0] * 10, 0: [1] * 10}, index=pd.RangeIndex(0, 100, 10)
34+
)
35+
36+
tm.assert_frame_equal(groups[0], expected_value)
37+
38+
2239
def test_apply_issues():
2340
# GH 5788
2441

0 commit comments

Comments
 (0)