Skip to content

Commit 41e43fe

Browse files
committed
fix tests
1 parent 70266e1 commit 41e43fe

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

xarray/core/groupby.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -587,7 +587,7 @@ def _flox_reduce(self, dim, **kwargs):
587587
):
588588
raise ValueError(f"cannot reduce over dimensions {dim}.")
589589

590-
# TODO: handle bins=N in dask_groupby
590+
# TODO: handle bins=N in flox
591591
if self._bins is not None:
592592
expected_groups = (self._bins,)
593593
isbin = (True,)
@@ -600,6 +600,9 @@ def _flox_reduce(self, dim, **kwargs):
600600
# note min_count makes no sense in the xarray world
601601
# as a kwarg for count, so this should be OK
602602
kwargs["min_count"] = 1
603+
# empty bins have np.nan regardless of dtype
604+
# flox's default would not set np.nan for integer dtypes
605+
kwargs.setdefault("fill_value", np.nan)
603606
else:
604607
expected_groups = (self._unique_coord.values,)
605608
isbin = False

xarray/tests/test_units.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5320,8 +5320,12 @@ def test_computation_objects(self, func, variant, dtype):
53205320
units = extract_units(ds)
53215321

53225322
args = [] if func.name != "groupby" else ["y"]
5323-
expected = attach_units(func(strip_units(ds)).mean(*args), units)
5324-
actual = func(ds).mean(*args)
5323+
# Doesn't work with flox because pint doesn't implement
5324+
# ufunc.reduceat or np.bincount
5325+
# kwargs = {"engine": "numpy"} if "groupby" in func.name else {}
5326+
kwargs = {}
5327+
expected = attach_units(func(strip_units(ds)).mean(*args, **kwargs), units)
5328+
actual = func(ds).mean(*args, **kwargs)
53255329

53265330
assert_units_equal(expected, actual)
53275331
assert_allclose(expected, actual)

0 commit comments

Comments
 (0)