8000 Hypothesis strategy for generating Variable objects by TomNicholas · Pull Request #8404 · pydata/xarray · GitHub
[go: up one dir, main page]

Skip to content

Hypothesis strategy for generating Variable objects #8404

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

Merged
merged 176 commits into from
Dec 5, 2023
Merged
Changes from 1 commit
Commits
Show all changes
176 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 8000 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
fd6aa06
remove every strategy beyond variables
TomNicholas Nov 2, 2023
df3341e
variable strategy now accepts callable generating array strategies
TomNicholas Nov 2, 2023
de4de8f
use only readable unicode characters in names
TomNicholas Nov 2, 2023
af14dc2
examples
TomNicholas Nov 2, 2023
d001dbb
only use unicode characters that docs can deal with
TomNicholas Nov 2, 2023
d4c9cb5
docs: dataarrays -> variables
TomNicholas Nov 2, 2023
7983e34
update tests for variables strategy
TomNicholas Nov 2, 2023
2ad7bb0
test values in attrs dict
TomNicholas Nov 2, 2023
a9f7cd5
duck array type examples
TomNicholas Nov 2, 2023
49a1c64
altered whatsnew
TomNicholas Nov 2, 2023
c1f1974
maybe fix mypy
TomNicholas Nov 2, 2023
6482ad3
fix some mypy errors
TomNicholas Nov 2, 2023
95cab79
more typing changes
TomNicholas Nov 2, 2023
839c4f0
fix import
TomNicholas Nov 2, 2023
ded711a
skip doctests in docstrings
TomNicholas Nov 2, 2023
f3c80ed
fix link to duckarrays page
TomNicholas Nov 2, 2023
010f28c
don't actually try to run cupy in docs env
TomNicholas Nov 2, 2023
4b07992
missed a skip
TomNicholas Nov 2, 2023
ba99afa
okwarning
TomNicholas Nov 2, 2023
700d652
just remove the cupy example
TomNicholas Nov 2, 2023
0e01d76
ensure shape is always passed to array_strategy_fn
TomNicholas Nov 2, 2023
79f40f0
test using make_strategies_namespace
TomNicholas Nov 3, 2023
4ff57ec
test catching array_strategy_fn that returns different dtype
TomNicholas Nov 3, 2023
959222e
test catching array_strategy_fn that returns different shape
TomNicholas Nov 3, 2023
78825c4
generalise test of attrs strategy
TomNicholas Nov 3, 2023
2418a61
remove misguided comments
TomNicholas Nov 3, 2023
331f521
Merge branch 'main' into hypothesis-strategies-variable
TomNicholas Nov 3, 2023
adca1d2
save working version of test_mean
TomNicholas Nov 4, 2023
14998c1
expose unique_subset_of
TomNicholas Nov 4, 2023
71f01f9
generalize unique_subset_of to handle iterables
TomNicholas Nov 4, 2023
9c10895
type hint unique_subset_of using overloads
TomNicholas Nov 4, 2023
2833f01
use iterables in test_mean example
TomNicholas Nov 4, 2023
1ddc515
test_mean example in docs now uses iterable of dimension_names
TomNicholas Nov 4, 2023
618bfea
fix some warnings in docs build
TomNicholas Nov 4, 2023
fe1ff1a
example of passing list to unique_subset_of
TomNicholas Nov 4, 2023
2e038ea
fix import in docs page
TomNicholas Nov 4, 2023
04c3dc1
try to satisfy sphinx
TomNicholas Nov 4, 2023
cf35fb9
Minor corrections to docs
TomNicholas Nov 4, 2023
4811e8a
Add supported_dtypes to list of public strategies in docs
TomNicholas Nov 5, 2023
a036253
Generate number of dimensions in test_given_arbitrary_dims_list
TomNicholas Nov 5, 2023
054a0dc
Update minimum version of hypothesis
TomNicholas Nov 5, 2023
ececa07
fix incorrect indentation in autosummary
TomNicholas Nov 10, 2023
0fa090d
link to docs page on testing
TomNicholas Nov 11, 2023
a9ac6f1
use warning imperative for array API non-compliant dtypes
TomNicholas Nov 11, 2023
43831ce
fix bugs in sparse examples
TomNicholas Nov 11, 2023
62dbe88
add tag for array API standard info
TomNicholas Nov 11, 2023
af5eb25
move no-dependencies-on-other-values-inputs to given decorator
TomNicholas Nov 11, 2023
dc78254
generate everything that can be generated
TomNicholas Nov 11, 2023
5822390
fix internal link to page on strategies
TomNicholas Nov 11, 2023
eeb6b32
split up TypeError messages for each arg
TomNicholas Nov 11, 2023
e13c6ac
use hypothesis.errors.InvalidArgument
TomNicholas Nov 11, 2023
a169e1f
generalize tests for generating specific number of dimensions
TomNicholas Nov 11, 2023
46b36b9
fix some typing errors
TomNicholas Nov 11, 2023
00ed3d6
test that reduction example in docs actually works
TomNicholas Nov 12, 2023
d265ddb
fix typing errors
TomNicholas Nov 12, 2023
0e872a8
simply generation of sparse arrays in example
TomNicholas Nov 12, 2023
a941e60
Merge branch 'main' into hypothesis-strategies-variable
TomNicholas Nov 12, 2023
3d43ed6
fix impot in docs example
TomNicholas Nov 13, 2023
6c912d2
Merge branch 'main' into hypothesis-strategies-variable
TomNicholas Nov 13, 2023
bdf3aed
correct type hints in sparse example
TomNicholas Nov 13, 2023
afd526d
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Nov 13, 2023
6bbd13b
Use .copy in convert_to_sparse
TomNicholas Nov 13, 2023
29ecd7d
Use st.builds in sparse example
TomNicholas Nov 13, 2023
631e810
correct intersphinx link in whatsnew
TomNicholas Nov 13, 2023
c613027
Merge branch 'hypothesis-strategies-variable' of https://github.com/T…
TomNicholas Nov 13, 2023
4412d98
rename module containing assertion functions
TomNicholas Nov 13, 2023
1ea0dcf
clarify sentence
TomNicholas Nov 13, 2023
cf1a45e
add general ImportError if hypothesis not installed
TomNicholas Nov 13, 2023
ea738cd
add See Also link to strategies docs page from docstring of every str…
TomNicholas Nov 14, 2023
79b0094
typo in ImportError message
TomNicholas Nov 14, 2023
c6d43ca
Merge branch 'main' into hypothesis-strategies-variable
TomNicholas Nov 15, 2023
00079bd
Merge branch 'main' into hypothesis-strategies-variable
TomNicholas Dec 4, 2023
cbcd486
remove extra blank lines in examples
TomNicholas Dec 5, 2023
69ddd08
remove smallish_arrays
TomNicholas Dec 5, 2023
ea90162
Merge branch 'main' into hypothesis-strategies-variable
TomNicholas Dec 5, 2023
File filter

Filter by extension

Filter by extension

8000
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
types for dataarrays strategy
  • Loading branch information
TomNicholas committed Aug 13, 2022
commit d0406a2a0178c860cd8a85fae09cd0ac64674f10
41 changes: 17 additions & 24 deletions xarray/testing/strategies.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import pandas as pd

import string
from typing import Any, Callable, List, Mapping, Optional, Sequence, Set, Tuple, Union

Expand Down Expand Up @@ -114,8 +116,8 @@ def dimension_names(
@st.composite
def variables(
draw: st.DrawFn,
dims: Union[Sequence[str], st.SearchStrategy[str]] = None,
data: Union[T_Array, st.SearchStrategy[T_Array], None] = None,
dims: Union[Sequence[str], st.SearchStrategy[str]] = None,
attrs: Union[Mapping, st.SearchStrategy[Mapping], None] = None,
convert: Callable[[np.ndarray], T_Array] = lambda a: a,
) -> st.SearchStrategy[xr.Variable]:
Expand Down Expand Up @@ -145,6 +147,8 @@ def variables(
"Passing strategies for both dims and data could generate inconsistent contents for Variable"
)

# TODO remove this handling of non-strategies in favour of passing `st.just(value)`

if data is not None and isinstance(data, st.SearchStrategy):
data = draw(data)
if dims is not None and isinstance(dims, st.SearchStrategy):
Expand Down Expand Up @@ -185,34 +189,23 @@ def variables(
@st.composite
def dataarrays(
draw: st.DrawFn,
create_data: Callable,
*,
min_dims=1,
max_dims=3,
min_size=1,
max_size=3,
dtypes=None,
data: Union[T_Array, st.SearchStrategy[T_Array], None] = None,
coords: Union[Sequence[Union[xr.DataArray, pd.Index]], Mapping[str, xr.Variable]] = None,
dims: Union[Sequence[str], st.SearchStrategy[str]] = None,
name: str = None,
attrs: Union[Mapping, st.SearchStrategy[Mapping], None] = None,
convert: Callable[[np.ndarray], T_Array] = lambda a: a,
) -> st.SearchStrategy[xr.DataArray]:

name = draw(st.none() | st.text(min_size=1))
if dtypes is None:
dtypes = all_dtypes

sizes = st.lists(
elements=st.tuples(st.text(min_size=1), st.integers(min_size, max_size)),
min_size=min_dims,
max_size=max_dims,
unique_by=lambda x: x[0],
)
drawn_sizes = draw(sizes)
dims, shape = zip(*drawn_sizes)

data = draw(create_data(shape, dtypes))
if name is None:
name = draw(st.none() | st.text(min_size=1))

return xr.DataArray(
data=data,
data=convert(data),
coords=coords,
name=name,
dims=dims,
attrs=attrs,
)


Expand All @@ -229,7 +222,7 @@ def datasets(
max_vars=3,
) -> st.SearchStrategy[xr.Dataset]:

dtypes = st.just(draw(all_dtypes))
dtypes = st.just(draw(valid_dtypes))
names = st.text(min_size=1)
sizes = dimension_sizes(
min_size=min_size, max_size=max_size, min_dims=min_dims, max_dims=max_dims
Expand Down
0