Skip to content

TST: groupby apply with indexing and column aggregation returns the column #7002 #34647

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 12 commits into from
Jun 14, 2020
Merged
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion pandas/tests/groupby/test_apply.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ def test_group_apply_once_per_group(df, group_names):
# once per group

names = []

# cannot parameterize over the functions since they need external
# `names` to detect side effects

Expand Down Expand Up @@ -683,7 +684,6 @@ def func_with_date(batch):


def test_gb_apply_list_of_unequal_len_arrays():

# GH1738
df = DataFrame(
{
Expand Down Expand Up @@ -961,3 +961,17 @@ def fn(x):
name="col2",
)
tm.assert_series_equal(result, expected)


def test_apply_function_with_indexing_return_column():
# GH: 7002
df = DataFrame(
{
"foo1": ["one", "two", "two", "three", "one", "two"],
"foo2": np.random.randn(6),
}
)
result = df.groupby("foo1", as_index=False).apply(lambda x: x.mean())
expected = df.groupby("foo1", as_index=False).mean()
tm.assert_frame_equal(result, expected)
assert "foo1" in result.columns