forked from xarray-contrib/xarray-array-testing
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreduction.py
More file actions
27 lines (20 loc) · 883 Bytes
/
Copy pathreduction.py
File metadata and controls
27 lines (20 loc) · 883 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
from contextlib import nullcontext
import hypothesis.strategies as st
import pytest
import xarray.testing.strategies as xrst
from hypothesis import given
from xarray_array_testing.base import DuckArrayTestMixin
class ReductionTests(DuckArrayTestMixin):
@staticmethod
def expected_errors(op, **parameters):
return nullcontext()
@pytest.mark.parametrize("op", ["mean", "sum", "prod", "std", "var"])
@given(st.data())
def test_variable_reduction(self, op, data):
variable = data.draw(xrst.variables(array_strategy_fn=self.array_strategy_fn))
with self.expected_errors(op, variable=variable):
# compute using xr.Variable.<OP>()
actual = getattr(variable, op)().data
# compute using xp.<OP>(array)
expected = getattr(self.xp, op)(variable.data)
self.assert_equal(actual, expected)