Skip to content

Commit

Permalink
fix pydata#3141 add cumsum to DatasetGroupBy
Browse files Browse the repository at this point in the history
:
  • Loading branch information
VladSkripniuk committed Oct 19, 2019
1 parent 16fdac9 commit 28dd667
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
1 change: 1 addition & 0 deletions xarray/core/groupby.py
Original file line number Diff line number Diff line change
Expand Up @@ -859,3 +859,4 @@ def assign(self, **kwargs):

ops.inject_reduce_methods(DatasetGroupBy)
ops.inject_binary_ops(DatasetGroupBy)
ops.inject_cum_methods(DatasetGroupBy)
17 changes: 17 additions & 0 deletions xarray/tests/test_groupby.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,4 +202,21 @@ def test_da_groupby_assign_coords():
assert_identical(expected, actual2)


def test_da_groupby_cumsum():
ds = xr.Dataset(
{"foo": (("x",), [7, 3, 1, 1, 1, 1, 1])},
coords={"x": [0, 1, 2, 3, 4, 5, 6], "group_id": ("x", [0, 0, 1, 1, 2, 2, 2])},
)
actual = ds.groupby("group_id").cumsum(dim="x")
expected = xr.Dataset(
{
"foo": (("x",), [7, 10, 1, 2, 1, 2, 3]),
"group_id": (("x",), [0, 0, 1, 1, 2, 2, 2]),
},
coords={"x": [0, 1, 2, 3, 4, 5, 6]},
)

assert_identical(expected, actual)


# TODO: move other groupby tests from test_dataset and test_dataarray over here

0 comments on commit 28dd667

Please sign in to comment.