Strategies
Strategies¶
zarr.testing.strategies ¶
array_shapes
module-attribute
¶
array_shapes = array_shapes(
max_dims=4, min_side=3, max_side=5
) | array_shapes(max_dims=4, min_side=0)
attrs
module-attribute
¶
attrs: SearchStrategy[Mapping[str, JSON] | None] = (
none() | dictionaries(_attr_keys, _attr_values)
)
short_node_names
module-attribute
¶
short_node_names = filter(
lambda name: lower() != "zarr.json"
)
zarr_key_chars
module-attribute
¶
zarr_key_chars = sampled_from(
".-0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz"
)
array_metadata ¶
array_metadata(
draw: DrawFn,
*,
array_shapes: Callable[
..., SearchStrategy[tuple[int, ...]]
] = array_shapes,
zarr_formats: SearchStrategy[ZarrFormat] = zarr_formats,
attributes: SearchStrategy[
Mapping[str, JSON] | None
] = attrs,
) -> ArrayV2Metadata | ArrayV3Metadata
Source code in zarr/testing/strategies.py
arrays ¶
arrays(
draw: DrawFn,
*,
shapes: SearchStrategy[tuple[int, ...]] = array_shapes,
compressors: SearchStrategy = compressors,
stores: SearchStrategy[StoreLike] = stores,
paths: SearchStrategy[str] = paths(),
array_names: SearchStrategy = array_names,
arrays: SearchStrategy | None = None,
attrs: SearchStrategy = attrs,
zarr_formats: SearchStrategy = zarr_formats,
) -> AnyArray
Source code in zarr/testing/strategies.py
basic_indices ¶
basic_indices(
draw: DrawFn,
*,
shape: tuple[int, ...],
min_dims: int = 0,
max_dims: int | None = None,
allow_newaxis: TrueOrFalse = False,
allow_ellipsis: TrueOrFalse = True,
) -> Any
Basic indices without unsupported negative slices.
Source code in zarr/testing/strategies.py
chunk_paths ¶
Source code in zarr/testing/strategies.py
chunk_shapes ¶
Source code in zarr/testing/strategies.py
clear_store ¶
dimension_names ¶
Source code in zarr/testing/strategies.py
dtypes ¶
Source code in zarr/testing/strategies.py
end_slices ¶
A strategy that slices ranges that include the last chunk. This is intended to stress-test handling of a possibly smaller last chunk.
Source code in zarr/testing/strategies.py
is_negative_slice ¶
key_ranges ¶
key_ranges(
keys: SearchStrategy[str] = node_names,
max_size: int = maxsize,
) -> SearchStrategy[list[tuple[str, RangeByteRequest]]]
Function to generate key_ranges strategy for get_partial_values() returns list strategy w/ form::
[(key, (range_start, range_end)),
(key, (range_start, range_end)),...]
Source code in zarr/testing/strategies.py
keys ¶
np_array_and_chunks ¶
np_array_and_chunks(
draw: DrawFn,
*,
arrays: SearchStrategy[NDArray[Any]] = numpy_arrays(),
) -> tuple[ndarray, tuple[int, ...]]
A hypothesis strategy to generate small sized random arrays.
Returns: a tuple of the array and a suitable random chunking for it.
Source code in zarr/testing/strategies.py
numpy_arrays ¶
numpy_arrays(
draw: DrawFn,
*,
shapes: SearchStrategy[tuple[int, ...]] = array_shapes,
dtype: dtype[Any] | None = None,
) -> NDArray[Any]
Generate numpy arrays that can be saved in the provided Zarr format.
Source code in zarr/testing/strategies.py
orthogonal_indices ¶
orthogonal_indices(
draw: DrawFn, *, shape: tuple[int, ...]
) -> tuple[
tuple[ndarray[Any, Any], ...],
tuple[ndarray[Any, Any], ...],
]
Strategy that returns (1) a tuple of integer arrays used for orthogonal indexing of Zarr arrays. (2) a tuple of integer arrays that can be used for equivalent indexing of numpy arrays
Source code in zarr/testing/strategies.py
paths ¶
safe_unicode_for_dtype ¶
Generate UTF-8-safe text constrained to max_len of dtype.
Source code in zarr/testing/strategies.py
shard_shapes ¶
shard_shapes(
draw: DrawFn,
*,
shape: tuple[int, ...],
chunk_shape: tuple[int, ...],
) -> tuple[int, ...]
Source code in zarr/testing/strategies.py
simple_arrays ¶
simple_arrays(
draw: DrawFn,
*,
shapes: SearchStrategy[tuple[int, ...]] = array_shapes,
) -> Any