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
33 lines (23 loc) · 1.01 KB
/
reduction.py
File metadata and controls
33 lines (23 loc) · 1.01 KB
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
28
29
30
31
32
33
from contextlib import nullcontext
import hypothesis.strategies as st
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()
@given(st.data())
def test_variable_mean(self, data):
variable = data.draw(xrst.variables(array_strategy_fn=self.array_strategy_fn))
with self.expected_errors("mean", variable=variable):
actual = variable.mean().data
expected = self.xp.mean(variable.data)
self.assert_equal(actual, expected)
@given(st.data())
def test_variable_prod(self, data):
variable = data.draw(xrst.variables(array_strategy_fn=self.array_strategy_fn))
with self.expected_errors("prod", variable=variable):
actual = variable.prod().data
expected = self.xp.prod(variable.data)
self.assert_equal(actual, expected)