-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathreduction.py
More file actions
25 lines (19 loc) · 834 Bytes
/
reduction.py
File metadata and controls
25 lines (19 loc) · 834 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
from contextlib import nullcontext
from functools import partial
import pytest
import xarray.testing.strategies as xrst
from xarray_array_testing.base import DuckArrayTestMixin
from xarray_array_testing.decorator import delayed_given
class ReductionTests(DuckArrayTestMixin):
@staticmethod
def expected_errors(op, **parameters):
return nullcontext()
@pytest.mark.parametrize("op", ["mean", "sum", "prod", "std", "var"])
@delayed_given(partial(xrst.variables))
def test_variable(self, op, variable):
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)