Skip to content

Commit

Permalink
Merge pull request #301 from PyPSA/groupby-ndim
Browse files Browse the repository at this point in the history
test: add test for ndim groupby
  • Loading branch information
FabianHofmann authored Jun 10, 2024
2 parents d3703fc + 62158fc commit ba30093
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions test/test_linear_expression.py
Original file line number Diff line number Diff line change
Expand Up @@ -667,6 +667,18 @@ def test_linear_expression_groupby(v, use_fallback):
assert grouped.nterm == 10


@pytest.mark.parametrize("use_fallback", [True])
def test_linear_expression_groupby_ndim(z, use_fallback):
# TODO: implement fallback for n-dim groupby, see https://github.com/PyPSA/linopy/issues/299
expr = 1 * z
groups = xr.DataArray([[1, 1, 2], [1, 3, 3]], coords=z.coords)
grouped = expr.groupby(groups).sum(use_fallback=use_fallback)
assert "group" in grouped.dims
# there are three groups, 1, 2 and 3, the largest group has 3 elements
assert (grouped.data.group == [1, 2, 3]).all()
assert grouped.nterm == 3


@pytest.mark.parametrize("use_fallback", [True, False])
def test_linear_expression_groupby_with_name(v, use_fallback):
expr = 1 * v
Expand Down

0 comments on commit ba30093

Please sign in to comment.