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
Hypothesis strategies in xarray.testing.strategies #6908
base: main
Are you sure you want to change the base?
Conversation
I also added my chunking strategy from HypothesisWorks/hypothesis#3433 |
for more information, see https://pre-commit.ci
…s/xarray into hypothesis-strategies
for more information, see https://pre-commit.ci
@Zac-HD if I could request one more review please! The two remaining problems for me are:
|
Absolutely! Some quick comments this evening; I would also like to do a full review again before merge but that might be next week or weekend - I'm out for a conference from early Thursday.
Replied in the thread above.
I'd be pretty surprised if that was related, |
if draw( | ||
st.booleans() | ||
): # Allow for no coordinate variables - explicit possibility not to helps with shrinking |
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.
if draw( | |
st.booleans() | |
): # Allow for no coordinate variables - explicit possibility not to helps with shrinking | |
# Allow for no coordinate variables - explicit possibility not to helps with shrinking | |
if draw(st.booleans()): |
doc/user-guide/testing.rst
Outdated
but building a dataset from scratch (i.e. method (2)) requires building the dataset object in such as way that all of | ||
the data variables have compatible dimensions. You can build up a dictionary of the form ``{var_name: data_variable}`` | ||
yourself, or you can use the ``data_vars`` argument to the ``data_variables`` strategy (TODO): | ||
|
||
.. ipython:: python | ||
:okexcept: | ||
|
||
sparse_data_vars = xrst.data_variables(data=sparse_arrays()) | ||
sparse_datasets = xrst.datasets(data_vars=sparse_data_vars) | ||
|
||
sparse_datasets.example() |
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 had intended to push .pin
in some form upstream, but I of course forgot about the other types of strategies so I can see why that would not be desirable.
Putting the code into the definition of the composite strategy is much better than what I had before (constructing the examples using data.draw
directly in the test), so that would be fine with me.
Do you know if it is possible to use make_strategies_namespace
with additional parameters to the array's constructor, like units for pint
or chunks for dask
? I guess if we use the pint_arrays
function from above we could use partial
for this (and anyway, pint
does not implement __array_namespace__
at the moment).
How do we move this forward? Even Xarray objects with just numpy arrays would be quite useful |
I think #8404 made a lot of progress on this, including shipping the user-facing documentation. If you wanted to open a PR rebasing this set of changes on main, I think that might be most of the remaining work. |
So I just did a monster merge of
It's mostly just dealing with the above and also making sure we can generate sets of variables with alignable dimensions efficiently. We also probably should think about what we want the signatures of the more complicated strategies to be: e.g. are we wanting to pass
A lot of the work that went into #8404 was working out how to make it general enough to handle non-numpy arrays. |
Adds a whole suite of hypothesis strategies for generating xarray objects, inspired by and separated out from the new hypothesis strategies in #4972. They are placed into the namespace
xarray.testing.strategies
, and publicly mentioned in the API docs, but with a big warning message. There is also a newtesting
page in the user guide documenting how to use these strategies.whats-new.rst
api.rst
EDIT: A
variables
strategy and user-facing documentation were shipped in #8404