Uh oh!
There was an error while loading. Please reload this page.
Duckarray tests for constructors and properties - #6903
Conversation
for more information, see https://pre-commit.ci
…Nicholas/xarray into duckarray-tests-constructors
@keewis I've come back to this PR now that #8404 is merged. I have:
I just wanted to show you to see what you thought of this approach now. |
| @staticmethod | ||
| @abstractmethod | ||
| def array_strategy_fn( | ||
| *, shape: "_ShapeLike", dtype: "_DTypeLikeNested" | ||
| ) -> st.SearchStrategy[T_DuckArray]: | ||
| # TODO can we just make this an attribute? | ||
| ... | ||
There was a problem hiding this comment.
I would like to just do this in the subclassed tests:
classVariableConstructorTestsarray_strategy_fn= ...but then would I need to make array_strategy_fn an abstract property?
| @pytest.mark.parametrize( | ||
| "method", | ||
| ( | ||
| "all", | ||
| "any", | ||
| # "cumprod", # not in array API | ||
| # "cumsum", # not in array API | ||
| # "max", # only in array API for real numeric dtypes | ||
| # "max", # only in array API for real floating point dtypes | ||
| # "median", # not in array API | ||
| # "min", # only in array API for real numeric dtypes | ||
| # "prod", # only in array API for numeric dtypes | ||
| # "std", # TypeError: std() got an unexpected keyword argument 'ddof' | ||
| # "sum", # only in array API for numeric dtypes | ||
| # "var", # TypeError: std() got an unexpected keyword argument 'ddof' |
There was a problem hiding this comment.
Clearly we need to be able to test certain reductions with only certain dtypes
| def test_construct(self, data) -> None: | ||
| shape = data.draw(self.shapes) | ||
| dtype = data.draw(self.dtypes) | ||
| arr = data.draw(self.array_strategy_fn(shape=shape, dtype=dtype)) |
There was a problem hiding this comment.
You can't use strategies.variables to test the constructor because strategies.variables has a call to the constructor inside it, so you end up not being able to access the original raw array that you want to use as the "expected" value.
TomNicholas
commented
Dec 31, 2023
Okay I'm a bit stumped by how to do this. I want some test setup where:
I was hoping to do this using some combination of upstream test classes, |
If you look at #4972, there's a new mark that applies other marks, like Edit: although fixtures are not that different from glorified globals |
TomNicholas
commented
Dec 31, 2023
Interesting, thank you!
Also a good idea, but I think I need to override the dtype fixtures on a per-parametrization level... |
keewis
commented
Dec 31, 2023
Depends on what you want to parametrize, I guess. In general, though, I'm starting to lean towards not parametrizing the functions to test: |
Builds on top of #4972 to add tests for
Variable/DataArray/Datasetconstructors and properties when wrapping duck arrays.Adds a file
xarray/tests/duckarrays/base/constructors.pywhich contains new test base classes.Also uses those new base classes to test Sparse array integration (not yet tried for pint integration).
whats-new.rstapi.rst