Skip to content

Commit 7f2654b

Browse files
committed
Merge branch 'main' into cubed_xarray_tests
2 parents 72fd4bf + 6a83950 commit 7f2654b

File tree

1 file changed

+7
-15
lines changed

1 file changed

+7
-15
lines changed

xarray_array_testing/reduction.py

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from contextlib import nullcontext
22

33
import hypothesis.strategies as st
4+
import pytest
45
import xarray.testing.strategies as xrst
56
from hypothesis import HealthCheck, given, note, settings
67

@@ -14,27 +15,18 @@ def expected_errors(op, **parameters):
1415

1516
# TODO understand the differing executors health check error
1617
@settings(suppress_health_check=[HealthCheck.differing_executors])
18+
@pytest.mark.parametrize("op", ["mean", "sum", "prod", "std", "var"])
1719
@given(st.data())
18-
def test_variable_mean(self, data):
20+
def test_variable_numerical_reduce(self, op, data):
1921
variable = data.draw(xrst.variables(array_strategy_fn=self.array_strategy_fn))
2022

2123
note(f"note: {variable}")
2224

2325
with self.expected_errors("mean", variable=variable):
24-
actual = variable.mean().data
25-
expected = self.xp.mean(variable.data)
26-
27-
assert isinstance(actual, self.array_type), type(actual)
28-
self.assert_equal(actual, expected)
29-
30-
@settings(suppress_health_check=[HealthCheck.differing_executors])
31-
@given(st.data())
32-
def test_variable_prod(self, data):
33-
variable = data.draw(xrst.variables(array_strategy_fn=self.array_strategy_fn))
34-
35-
with self.expected_errors("prod", variable=variable):
36-
actual = variable.prod().data
37-
expected = self.xp.prod(variable.data)
26+
# compute using xr.Variable.<OP>()
27+
actual = getattr(variable, op)().data
28+
# compute using xp.<OP>(array)
29+
expected = getattr(self.xp, op)(variable.data)
3830

3931
assert isinstance(actual, self.array_type), type(actual)
4032
self.assert_equal(actual, expected)

0 commit comments

Comments
 (0)