Skip to content
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
2 changes: 1 addition & 1 deletion xarray/core/groupby.py
Original file line number Diff line number Diff line change
Expand Up @@ -828,7 +828,7 @@ def groups(self) -> dict[GroupKey, GroupIndex]:
self._groups = dict(
zip(
self.encoded.unique_coord.data,
self.encoded.group_indices,
tuple(g for g in self.encoded.group_indices if g),
strict=True,
)
)
Expand Down
10 changes: 10 additions & 0 deletions xarray/tests/test_groupby.py
Original file line number Diff line number Diff line change
Expand Up @@ -3200,6 +3200,16 @@ def test_multiple_grouper_unsorted_order() -> None:
assert_identical(actual2, expected2)


def test_multiple_grouper_empty_groups() -> None:
ds = xr.Dataset(
{"foo": (("x", "y"), np.random.rand(4, 3))},
coords={"x": [10, 20, 30, 40], "letters": ("x", list("abba"))},
)

groups = ds.groupby(x=BinGrouper(bins=[5, 15, 25]), letters=UniqueGrouper())
assert len(groups.groups) == 2
Comment thread
dcherian marked this conversation as resolved.


def test_groupby_multiple_bin_grouper_missing_groups() -> None:
from numpy import nan

Expand Down
Loading