Skip to content

Commit 9dca069

Browse files
authored
TST: groupby apply with indexing and column aggregation returns the column #7002 (#34647)
1 parent 4f625a2 commit 9dca069

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

pandas/tests/groupby/test_apply.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -961,3 +961,16 @@ def fn(x):
961961
name="col2",
962962
)
963963
tm.assert_series_equal(result, expected)
964+
965+
966+
def test_apply_function_with_indexing_return_column():
967+
# GH: 7002
968+
df = DataFrame(
969+
{
970+
"foo1": ["one", "two", "two", "three", "one", "two"],
971+
"foo2": [1, 2, 4, 4, 5, 6],
972+
}
973+
)
974+
result = df.groupby("foo1", as_index=False).apply(lambda x: x.mean())
975+
expected = DataFrame({"foo1": ["one", "three", "two"], "foo2": [3.0, 4.0, 4.0]})
976+
tm.assert_frame_equal(result, expected)

0 commit comments

Comments
 (0)