Skip to content
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

Open
wants to merge 107 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 105 commits
Commits
Show all changes
107 commits
Select commit Hold shift + click to select a range
587ebb8
copied files defining strategies over to this branch
TomNicholas Aug 11, 2022
acbfa69
placed testing functions in their own directory
TomNicholas Aug 11, 2022
73d763f
moved hypothesis strategies into new testing directory
TomNicholas Aug 11, 2022
db2deff
begin type hinting strategies
TomNicholas Aug 11, 2022
746cfc8
renamed strategies for consistency with hypothesis conventions
TomNicholas Aug 11, 2022
03cd9de
added strategies to public API (with experimental warning)
TomNicholas Aug 11, 2022
2fe3583
strategies for chunking patterns
TomNicholas Aug 11, 2022
4db3629
rewrote variables strategy to have same signature as Variable constru…
TomNicholas Aug 13, 2022
14d11aa
test variables strategy
TomNicholas Aug 13, 2022
418a359
fixed most tests
TomNicholas Aug 13, 2022
c8a7d0e
added helpers so far to API docs
TomNicholas Aug 13, 2022
d48aceb
add hypothesis to docs CI env
TomNicholas Aug 13, 2022
a20e341
add todo about attrs
TomNicholas Aug 13, 2022
3a4816f
draft of new user guide page on testing
TomNicholas Aug 13, 2022
d0406a2
types for dataarrays strategy
TomNicholas Aug 13, 2022
65a222d
draft for chained chunking example
TomNicholas Aug 13, 2022
e1d718a
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Aug 13, 2022
57d0f5b
only accept strategy objects
TomNicholas Aug 14, 2022
82c734c
fixed failure with passing in two custom strategies that must be comp…
TomNicholas Aug 14, 2022
029f19a
syntax error in example
TomNicholas Aug 14, 2022
46895fe
allow sizes dict as argument to variables
TomNicholas Aug 15, 2022
50c62e9
copied subsequences_of strategy
TomNicholas Aug 15, 2022
e21555a
coordinate_variables generates non-dimensional coords
TomNicholas Aug 15, 2022
1688779
dataarrays strategy given nothing working!
TomNicholas Aug 15, 2022
0a29d32
improved docstrings
TomNicholas Aug 15, 2022
3259849
datasets strategy works (given nothing)
TomNicholas Aug 15, 2022
717fabe
Merge branch 'hypothesis-strategies' of https://github.com/TomNichola…
TomNicholas Aug 15, 2022
d76e5b6
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Aug 15, 2022
c25940c
pass dims or data to dataarrays() strategy
TomNicholas Aug 16, 2022
cd7b065
importorskip hypothesis in tests
TomNicholas Aug 16, 2022
742b18c
Merge branch 'hypothesis-strategies' of https://github.com/TomNichola…
TomNicholas Aug 16, 2022
8e548b1
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Aug 16, 2022
d1487d4
added warning about inefficient example generation
TomNicholas Aug 16, 2022
c8b53f2
Merge branch 'hypothesis-strategies' of https://github.com/TomNichola…
TomNicholas Aug 16, 2022
8bac610
remove TODO about deterministic examples in docs
TomNicholas Aug 17, 2022
cf3beb5
un-restrict names strategy
TomNicholas Aug 17, 2022
d991357
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Aug 17, 2022
a6405cf
removed convert kwarg
TomNicholas Aug 17, 2022
400ae3e
removed convert kwarg
TomNicholas Aug 17, 2022
3609a34
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Aug 17, 2022
63ad529
avoid using subsequences_of
TomNicholas Aug 17, 2022
4ffbcbd
refactored into separate function for unique subset of dims
TomNicholas Aug 17, 2022
469482d
removed subsequences_of
TomNicholas Aug 17, 2022
472de00
Merge branch 'hypothesis-strategies' of https://github.com/TomNichola…
TomNicholas Aug 17, 2022
ced1a9f
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Aug 17, 2022
a3c9ad0
fix draw(st.booleans())
TomNicholas Aug 17, 2022
b387304
Merge branch 'hypothesis-strategies' of https://github.com/TomNichola…
TomNicholas Aug 17, 2022
404111d
remove all references to chunking until chunks strategy merged upstre…
TomNicholas Aug 23, 2022
3764a7b
added example of complicated strategy for dims dict
TomNicholas Aug 23, 2022
9723e45
remove superfluous utils file
TomNicholas Aug 30, 2022
2e44860
removed elements strategy
TomNicholas Aug 30, 2022
1cc073b
removed np_arrays strategy from public API
TomNicholas Aug 30, 2022
603e6bb
min_ndims -> min_dims
TomNicholas Aug 30, 2022
63bb362
forbid non-matching dims and data completely
TomNicholas Aug 31, 2022
69ec230
simple test for data_variables strategy
TomNicholas Aug 31, 2022
e5c7e23
passing arguments to datasets strategy
TomNicholas Sep 2, 2022
fd3d357
Merge branch 'main' into hypothesis-strategies
TomNicholas Sep 2, 2022
52f2490
whatsnew
TomNicholas Sep 2, 2022
9b96470
add attrs strategy
TomNicholas Sep 2, 2022
41fe0b4
autogenerate attrs for all objects
TomNicholas Sep 2, 2022
0e53aa1
attempt to make attrs strategy quicker
TomNicholas Sep 2, 2022
f659b4b
extend deadline
TomNicholas Sep 2, 2022
d1be3ee
attempt to speed up attrs strategy
TomNicholas Sep 6, 2022
e88f5f0
promote all strategies to be functions
TomNicholas Sep 7, 2022
4b88887
valid_dtypes -> numeric_dtypes
TomNicholas Sep 7, 2022
2a1dc66
changed hypothesis error type
TomNicholas Sep 7, 2022
9bddcec
make all strategies keyword-arg only
TomNicholas Sep 7, 2022
b2887d4
min_length -> min_side
TomNicholas Sep 7, 2022
3b8e8ae
correct error type
TomNicholas Sep 7, 2022
0980061
remove coords kwarg
TomNicholas Sep 7, 2022
0313b3e
test different types of coordinates are sometimes generated
TomNicholas Sep 7, 2022
e6ebb1f
zip dict
TomNicholas Sep 7, 2022
4da8772
add dim_names kwarg to dimension_sizes strategy
TomNicholas Sep 7, 2022
e6d7a34
return a dict from _alignable_variables
TomNicholas Sep 7, 2022
5197d1b
Merge branch 'hypothesis-strategies' of https://github.com/TomNichola…
TomNicholas Sep 7, 2022
15812fd
add coord_names arg to coordinate_variables strategy
TomNicholas Sep 7, 2022
3dc9c7b
Merge branch 'main' into hypothesis-strategies
TomNicholas Sep 7, 2022
4374681
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Sep 7, 2022
0f0c4fb
change typing of dims arg
TomNicholas Sep 7, 2022
6a30af5
support dims as list to datasets strat when data not given
TomNicholas Sep 7, 2022
cac46dc
Merge branch 'hypothesis-strategies' of https://github.com/TomNichola…
TomNicholas Sep 7, 2022
177d908
put coord and data var generation in optional branch to try to improv…
TomNicholas Sep 7, 2022
5424e37
improve simple test example
TomNicholas Sep 7, 2022
c871273
add documentation on creating duck arrays
TomNicholas Sep 7, 2022
7730a27
okexcept for sparse examples
TomNicholas Sep 7, 2022
24549bc
fix sparse dataarrays example
TomNicholas Sep 7, 2022
3082a09
todo about building a duck array dataset
TomNicholas Sep 7, 2022
5df60dc
fix imports and cross-links
TomNicholas Sep 7, 2022
01078de
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Sep 7, 2022
53290e2
add hypothesis library to intersphinx mapping
TomNicholas Sep 8, 2022
bd2cb6e
fix many links
TomNicholas Sep 8, 2022
c5e83c2
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Sep 8, 2022
de26b2f
fixed all local mypy errors
TomNicholas Sep 9, 2022
f81e14f
move numpy strategies import
TomNicholas Sep 9, 2022
129e2c3
Merge branch 'hypothesis-strategies' of https://github.com/TomNichola…
TomNicholas Sep 9, 2022
601d9e2
Merge branch 'main' into hypothesis-strategies
TomNicholas Sep 10, 2022
af24af5
reduce sizes
TomNicholas Sep 10, 2022
9777c2a
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Sep 10, 2022
4dcbc60
Merge branch 'main' into hypothesis-strategies
TomNicholas Jul 20, 2023
7841dd5
fix some api links in docs
TomNicholas Jul 24, 2023
968ee72
Merge branch 'main' into hypothesis-strategies
TomNicholas Nov 2, 2023
a6fc063
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Nov 2, 2023
6a4a403
Merge branch 'main' into hypothesis-strategies
TomNicholas Apr 1, 2024
0b13771
remove np_arrays strategy
TomNicholas Apr 1, 2024
b44a4a2
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Apr 1, 2024
cdcfbf4
fix bad merge of whatsnew
TomNicholas Apr 1, 2024
0aab116
fix bad merge in strategies
TomNicholas Apr 1, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions doc/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1090,6 +1090,10 @@ See the :ref:`documentation page on testing <testing.hypothesis>` for a guide on
testing.strategies.dimension_sizes
testing.strategies.attrs
testing.strategies.variables
testing.strategies.coordinate_variables
testing.strategies.dataarrays
testing.strategies.data_variables
testing.strategies.datasets
testing.strategies.unique_subset_of

Exceptions
Expand Down
2 changes: 2 additions & 0 deletions doc/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,8 @@
# Example configuration for intersphinx: refer to the Python standard library.
intersphinx_mapping = {
"cftime": ("https://unidata.github.io/cftime", None),
"sparse": ("https://sparse.pydata.org/en/latest/", None),
"hypothesis": ("https://hypothesis.readthedocs.io/en/latest/", None),
"cubed": ("https://cubed-dev.github.io/cubed/", None),
"dask": ("https://docs.dask.org/en/latest", None),
"datatree": ("https://xarray-datatree.readthedocs.io/en/latest/", None),
Expand Down
7 changes: 6 additions & 1 deletion doc/user-guide/testing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ These strategies are accessible in the :py:mod:`xarray.testing.strategies` modul
testing.strategies.dimension_sizes
testing.strategies.attrs
testing.strategies.variables
testing.strategies.coordinate_variables
testing.strategies.dataarrays
testing.strategies.data_variables
testing.strategies.datasets
testing.strategies.unique_subset_of

These build upon the numpy and array API strategies offered in :py:mod:`hypothesis.extra.numpy` and :py:mod:`hypothesis.extra.array_api`:
Expand Down Expand Up @@ -89,7 +93,6 @@ In your tests however you should not use ``.example()`` - instead you should par
def test_function_that_acts_on_variables(var):
assert func(var) == ...


Chaining Strategies
~~~~~~~~~~~~~~~~~~~

Expand Down Expand Up @@ -145,6 +148,7 @@ objects your chained strategy will generate.
fixed_x_variable_y_maybe_z = st.fixed_dictionaries(
{"x": st.just(2), "y": st.integers(3, 4)}, optional={"z": st.just(2)}
)

fixed_x_variable_y_maybe_z.example()

special_variables = xrst.variables(dims=fixed_x_variable_y_maybe_z)
Expand All @@ -156,6 +160,7 @@ Here we have used one of hypothesis' built-in strategies :py:func:`hypothesis.st
strategy which generates mappings of dimension names to lengths (i.e. the ``size`` of the xarray object we want).
This particular strategy will always generate an ``x`` dimension of length 2, and a ``y`` dimension of
length either 3 or 4, and will sometimes also generate a ``z`` dimension of length 2.

By feeding this strategy for dictionaries into the ``dims`` argument of xarray's :py:func:`~st.variables` strategy,
we can generate arbitrary :py:class:`~xarray.Variable` objects whose dimensions will always match these specifications.

Expand Down
13 changes: 13 additions & 0 deletions doc/whats-new.rst
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,19 @@ Illviljan, Justus Magin, Katelyn FitzGerald, Kai Muehlbauer, Martin Durant, Maxi
New Features
~~~~~~~~~~~~

dcherian marked this conversation as resolved.
Show resolved Hide resolved
- Added a suite of hypothesis strategies for generating xarray objects containing arbitrary data, useful for testing.
Accessible under :py:func:`testing.strategies`, and documented in a new page on testing in the User Guide.
(:issue:`6911`, :pull:`6908`)
By `Tom Nicholas <https://github.com/TomNicholas>`_.
- Enable taking the mean of dask-backed :py:class:`cftime.datetime` arrays
(:pull:`6556`, :pull:`6940`). By `Deepak Cherian
<https://github.com/dcherian>`_ and `Spencer Clark
<https://github.com/spencerkclark>`_.
- Allow creating Xarray objects where a multidimensional variable shares its name
with a dimension. Examples include output from finite volume models like FVCOM.
(:issue:`2233`, :pull:`7989`)
By `Deepak Cherian <https://github.com/dcherian>`_ and `Benoit Bovy <https://github.com/benbovy>`_.

- Use `opt_einsum <https://optimized-einsum.readthedocs.io/en/stable/>`_ for :py:func:`xarray.dot` by default if installed.
By `Deepak Cherian <https://github.com/dcherian>`_. (:issue:`7764`, :pull:`8373`).
- Add ``DataArray.dt.total_seconds()`` method to match the Pandas API. (:pull:`8435`).
Expand Down