Skip to content

Commit 35cf22c

Browse files
committed
cumulative reduce tests
`cumprod` / `cumulative_prod` are not part of the array API
1 parent 242a324 commit 35cf22c

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

xarray_array_testing/reduction.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,3 +67,18 @@ def test_variable_order_reduce_index(self, op, data):
6767

6868
assert isinstance(actual, self.array_type)
6969
self.assert_equal(actual, expected)
70+
71+
@pytest.mark.parametrize("op", ["cumsum", "cumprod"])
72+
@given(st.data())
73+
def test_variable_cumulative_reduce(self, op, data):
74+
array_api_names = {"cumsum": "cumulative_sum", "cumprod": "cumulative_prod"}
75+
variable = data.draw(xrst.variables(array_strategy_fn=self.array_strategy_fn))
76+
77+
with self.expected_errors(op, variable=variable):
78+
# compute using xr.Variable.<OP>()
79+
actual = getattr(variable, op)().data
80+
# compute using xp.<OP>(array)
81+
expected = getattr(self.xp, array_api_names[op])(variable.data)
82+
83+
assert isinstance(actual, self.array_type)
84+
self.assert_equal(actual, expected)

0 commit comments

Comments
 (0)