-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Duckarray tests for constructors and properties #6903
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
base: main
Are you sure you want to change the base?
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would like to just do this in the subclassed tests:
class VariableConstructorTests
array_strategy_fn = ...
but then would I need to make array_strategy_fn
an abstract property?
xarray/testing/duckarrays.py
Outdated
@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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
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 |
Interesting, thank you!
Also a good idea, but I think I need to override the dtype fixtures on a per-parametrization level... |
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/Dataset
constructors and properties when wrapping duck arrays.Adds a file
xarray/tests/duckarrays/base/constructors.py
which contains new test base classes.Also uses those new base classes to test Sparse array integration (not yet tried for pint integration).
whats-new.rst
api.rst