Skip to content

Commit acb1098

Browse files
committed
TEST: added test for agg with list-like func
1 parent 25e6a21 commit acb1098

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

pandas/tests/groupby/aggregate/test_other.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -512,3 +512,20 @@ def test_agg_category_nansum(observed):
512512
if observed:
513513
expected = expected[expected != 0]
514514
tm.assert_series_equal(result, expected)
515+
516+
517+
def test_agg_list_like_func():
518+
# GH 18473
519+
df = pd.DataFrame({'A': [str(x) for x in range(10)],
520+
'B': [str(x) for x in range(10)]})
521+
result = df.groupby('A', as_index=False, sort=False)\
522+
.aggregate({'B': lambda x: list(x)})
523+
expected = df.copy()
524+
expected['B'] = df['B'].apply(lambda x: list(x))
525+
tm.assert_frame_equal(result, expected)
526+
527+
# Testing normal func
528+
result = df.groupby('A', as_index=False, sort=False)\
529+
.aggregate({'B': lambda x: x})
530+
expected = df.copy()
531+
tm.assert_frame_equal(result, expected)

0 commit comments

Comments
 (0)