Skip to content

Commit

Permalink
Apply series name to result of SeriesGroupby.apply() (#8939)
Browse files Browse the repository at this point in the history
Closes #8899 

Applies the name of `SeriesGroupby.obj` to the results of a `SeriesGroupby.apply()` operation; originally, this would be left as `None`.

Authors:
  - Charles Blackmon-Luca (https://github.com/charlesbluca)

Approvers:
  - Sheilah Kirui (https://github.com/skirui-source)
  - Michael Wang (https://github.com/isVoid)

URL: #8939
  • Loading branch information
charlesbluca authored Aug 9, 2021
1 parent ed84e44 commit e8b05de
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
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

0 comments on commit e8b05de

Please sign in to comment.