-
Notifications
You must be signed in to change notification settings - Fork 2
Parametrize over different reduction operations #5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,7 @@ | ||
| from contextlib import nullcontext | ||
|
|
||
| import hypothesis.strategies as st | ||
| import pytest | ||
| import xarray.testing.strategies as xrst | ||
| from hypothesis import given | ||
|
|
||
|
|
@@ -12,22 +13,15 @@ class ReductionTests(DuckArrayTestMixin): | |
| def expected_errors(op, **parameters): | ||
| return nullcontext() | ||
|
|
||
| @pytest.mark.parametrize("op", ["mean", "sum", "prod", "std", "var"]) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. One of "min" or "max" would be good for checking that dtype is preserved. I'm not sure "std" adds much over "var". There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These were really just chosen in order to cover some known bugs with cubed. Specifically that cubed doesn't yet implement Eventually we would want a test suite that covers everything, this is just meant to be a proof-of-principle for discussing overall design. |
||
| @given(st.data()) | ||
| def test_variable_mean(self, data): | ||
| def test_variable_mean(self, op, 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) | ||
| 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) | ||