Skip to content

Commit 915a91b

Browse files
committed
Fix reduction along dimensions not in groupers.
xref #109
1 parent ccbda27 commit 915a91b

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

flox/xarray.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ def xarray_reduce(
241241
raise ValueError(f"Cannot reduce over absent dimensions {dim}.")
242242

243243
dims_not_in_groupers = tuple(d for d in dim if d not in grouper_dims)
244-
if dims_not_in_groupers == dim and not any(isbin):
244+
if dims_not_in_groupers == tuple(dim) and not any(isbin):
245245
# reducing along a dimension along which groups do not vary
246246
# This is really just a normal reduction.
247247
# This is not right when binning so we exclude.

tests/test_xarray.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,11 @@ def test_xarray_reduce_single_grouper(engine):
188188
actual = xarray_reduce(ds, ds.time.dt.month, func="mean", engine=engine)
189189
xr.testing.assert_allclose(actual, expected)
190190

191+
# reduce along other dimensions
192+
expected = ds.groupby("time.month").mean(("x", "y"))
193+
actual = xarray_reduce(ds, ds.time.dt.month, dim=["x", "y"], func="mean", engine=engine)
194+
xr.testing.assert_allclose(actual, expected)
195+
191196
# add data var with missing grouper dim
192197
ds["foo"] = ("bar", [1, 2, 3])
193198
expected = ds.groupby("time.month").mean()

0 commit comments

Comments
 (0)