1
1
from contextlib import nullcontext
2
2
3
+ import pytest
4
+
3
5
import hypothesis .strategies as st
4
6
import xarray .testing .strategies as xrst
5
7
from hypothesis import given
@@ -12,22 +14,15 @@ class ReductionTests(DuckArrayTestMixin):
12
14
def expected_errors (op , ** parameters ):
13
15
return nullcontext ()
14
16
17
+ @pytest .mark .parametrize ("op" , ["mean" , "sum" , "prod" , "std" , "var" ])
15
18
@given (st .data ())
16
- def test_variable_mean (self , data ):
17
- variable = data .draw (xrst .variables (array_strategy_fn = self .array_strategy_fn ))
18
-
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 ):
19
+ def test_variable_mean (self , op , data ):
27
20
variable = data .draw (xrst .variables (array_strategy_fn = self .array_strategy_fn ))
28
21
29
- with self .expected_errors ("prod" , variable = variable ):
30
- actual = variable .prod ().data
31
- expected = self .xp .prod (variable .data )
22
+ with self .expected_errors (op , variable = variable ):
23
+ # compute using xr.Variable.<OP>()
24
+ actual = getattr (variable , op )().data
25
+ # compute using xp.<OP>(array)
26
+ expected = getattr (self .xp , op )(variable .data )
32
27
33
28
self .assert_equal (actual , expected )
0 commit comments