Skip to content
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

Apply series name to result of SeriesGroupby.apply() #8939

Merged
merged 3 commits into from
Aug 9, 2021
Merged
Show file tree
Hide file tree
Changes from all 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
8 changes: 8 additions & 0 deletions python/cudf/cudf/core/groupby/groupby.py
Original file line number Diff line number Diff line change
Expand Up @@ -1214,6 +1214,14 @@ def agg(self, func):

return result

def apply(self, func):
result = super().apply(func)

# apply Series name to result
result.name = self.obj.name

return result


class Grouper(object):
def __init__(self, key=None, level=None):
Expand Down
10 changes: 10 additions & 0 deletions python/cudf/cudf/tests/test_groupby.py
Original file line number Diff line number Diff line change
Expand Up @@ -2086,3 +2086,13 @@ def test_groupby_describe(data, group):
expect = pdf.groupby(group).describe()

assert_groupby_results_equal(expect, got, check_dtype=False)


def test_groupby_apply_series_name():
def foo(x):
return x.sum()

got = make_frame(DataFrame, 3).groupby("x").y.apply(foo)
expect = make_frame(pd.DataFrame, 3).groupby("x").y.apply(foo)

assert expect.name == got.name