Skip to content

Commit

Permalink
Apply series name to result of SeriesGroupby.apply() (rapidsai#8939)
Browse files Browse the repository at this point in the history
Closes rapidsai#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: rapidsai#8939
  • Loading branch information
charlesbluca authored and shwina committed Aug 9, 2021
1 parent 9d61860 commit 0f109d7
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 @@ -1222,6 +1222,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 @@ -2104,3 +2104,13 @@ def test_groupby_first(data, agg):
expect = pdf.groupby("a").agg(agg)
got = gdf.groupby("a").agg(agg)
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 0f109d7

Please sign in to comment.