Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 491273d

Browse files
TomNicholaspre-commit-ci[bot]
andauthored
Parametrize over different reduction operations (#5)
* parametrize over different reduction operations * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent 003ffaf commit 491273d

File tree

1 file changed

+8
-14
lines changed

1 file changed

+8
-14
lines changed

‎xarray_array_testing/reduction.py‎

Lines changed: 8 additions & 14 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 given
67

@@ -12,22 +13,15 @@ class ReductionTests(DuckArrayTestMixin):
1213
def expected_errors(op, **parameters):
1314
return nullcontext()
1415

16+
@pytest.mark.parametrize("op", ["mean", "sum", "prod", "std", "var"])
1517
@given(st.data())
16-
def test_variable_mean(self, data):
18+
def test_variable_mean(self, op, data):
1719
variable = data.draw(xrst.variables(array_strategy_fn=self.array_strategy_fn))
1820

19-
with self.expected_errors("mean", variable=variable):
20-
actual = variable.mean().data
21-
expected = self.xp.mean(variable.data)
22-
23-
self.assert_equal(actual, expected)
24-
25-
@given(st.data())
26-
def test_variable_prod(self, data):
27-
variable = data.draw(xrst.variables(array_strategy_fn=self.array_strategy_fn))
28-
29-
with self.expected_errors("prod", variable=variable):
30-
actual = variable.prod().data
31-
expected = self.xp.prod(variable.data)
21+
with self.expected_errors(op, variable=variable):
22+
# compute using xr.Variable.<OP>()
23+
actual = getattr(variable, op)().data
24+
# compute using xp.<OP>(array)
25+
expected = getattr(self.xp, op)(variable.data)
3226

3327
self.assert_equal(actual, expected)

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /