Skip to content

Commit 4a72dd4

Browse files
d-v-bclaude
andauthored
feat(zarr-metadata): add Hypothesis strategies for metadata fields (zarr-developers#4575)
* feat(zarr-metadata): add Hypothesis strategies for metadata fields Add `zarr_metadata.testing.strategies`, behind a new `testing` extra. It ships Hypothesis strategies that draw valid Zarr v3 metadata fields, one for every codec, data type, chunk grid and chunk key encoding the package defines that holds no other field. - Each kind's strategy takes what its configurations depend on: a data type's fill values take its configuration, a chunk grid takes the array shape, and a codec takes the `Chunk` it is handed. - `fields` draws every envelope spelling the spec allows, or only the canonical one. - Strategies are a mapping keyed by definition, so an extension author can add strategies for their own definitions. The tests read every draw back in `CORE_AND_EXTENSIONS` and require no problems. They also check: - that every definition in scope has a strategy, apart from the three that hold nested fields; - reach, with targets derived from each configuration's TypedDict: each optional key present and absent, each `Literal` value, and a non-canonical spelling where one exists; - fill-value spellings and envelope forms. Strategies follow the spec where the package is looser. Core data types are drawn only as bare strings, and regular-grid chunk lengths are never zero ("Chunk sizes must be greater than zero"), although the package's rules accept both today. Assisted-by: ClaudeCode:claude-opus-5-5 * chore(zarr-metadata): number the strategies changelog fragment after #414 Assisted-by: ClaudeCode:claude-opus-5-5 * chore(zarr-metadata): number the strategies changelog fragment after PR 4575 The fragment was numbered after fork PR 414, so the changelog linked to an unrelated upstream PR. Assisted-by: ClaudeCode:claude-opus-5-5 * fix(zarr-metadata): draw a fresh empty configuration on every draw `st.just({})` (crc32c) and `st.just(EmptyConfiguration())` (every data type with nothing to configure) handed out one dict for every draw, and `fields` puts the configuration in the field as it is. A test that changed the configuration it drew changed every later draw, which Hypothesis reports as a flaky strategy. Both are now `st.builds(EmptyConfiguration)`. Export `Configurations` and `NOTHING_KNOWN` from `zarr_metadata.testing.strategies`: they appear in the signatures of `DefinitionStrategy.unconstrained` and `codec_configurations`. Assisted-by: ClaudeCode:claude-opus-5-5 * fix(zarr-metadata): check every drawn field, and draw hex scale_offset values `fields` read a field only when asked for the canonical spelling, so a caller's configurations the definition refuses were drawn silently in the default spelling. Every field is now read, in a scope built once per call rather than once per draw, and a refused one raises in both spellings. A definition no Zarr v3 scope holds, such as a v2 codec, is a `TypeError` when `fields` is called, not a `StopIteration` on a draw. A float `scale_offset` codec's `offset` and `scale` are fill values of its type, so they are now also drawn as the hex string of their bits. The docstring no longer claims a non-zero scale makes decoding defined: a tiny one still overflows. The codec chunk test now draws chunks of an unknown data type and with unknown lengths, which every codec takes. Assisted-by: ClaudeCode:claude-opus-5-5 * fix(zarr-metadata): draw scale_offset for every number type, and widen Strategies keys `scale_offset` drew nothing for complex numbers, numpy times and data types the package does not define, though its rules refuse only data types whose values are not numbers, and a numpy time "is compatible with any codec that supports arrays of signed 64-bit integers". A numpy time is now drawn as that integer, a complex number as a pair of finite floats, and a type the package does not define takes the identity configuration. None now means only what `CodecStrategy` says it means: no configuration takes the chunk. `Strategies` is keyed by `Any`: a mapping's key type is invariant, so a mapping an extension author builds, keyed by a `CodecDefinition`, was not a `Mapping[Definition[Any], ...]` to pyright. A rectilinear dimension of unknown length may now be drawn with no edges, which its rules accept. Assisted-by: ClaudeCode:claude-opus-5-5 * refactor(zarr-metadata): share the strategies' empty configuration and rank cap `EMPTY_CONFIGURATIONS` and `MAX_RANK` are defined once, in `_strategy`, rather than once in each module that draws them. A numpy time's `scale_offset` values are now drawn finite, never the integer numpy reads as `NaT`, as the docstring says. The `fields` docstring now says that a codec's chunk rules are not checked, since no chunk is known. Assisted-by: ClaudeCode:claude-opus-5-5 * test(zarr-metadata): cover scale_offset over a data type the package does not define The identity configuration `scale_offset` draws for a data type the package does not define had no test, since the chunk test draws only the package's own data types. A test now reads an extension `bfloat16` in a scope of its own and checks the codec takes every draw. Also splits the `_scope_of` error message across two literals and drops a doubled blank line in `_data_type`. Assisted-by: ClaudeCode:claude-opus-5-5 --------- Co-authored-by: Claude Opus 5.5 <[email protected]>
1 parent d105210 commit 4a72dd4

15 files changed

Lines changed: 1438 additions & 0 deletions

File tree

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Added `zarr_metadata.testing.strategies`, Hypothesis strategies that draw valid Zarr v3 metadata fields, behind a new `testing` extra (`pip install zarr-metadata[testing]`). There is one strategy for every codec, data type, chunk grid and chunk key encoding the package defines that holds no other field. `fields` draws every envelope spelling the spec allows, or only the canonical one with `spellings="canonical"`. Codecs can be drawn for the `Chunk` they are handed, chunk grids for an array shape, and fill values for a data type. The strategies are a mapping keyed by definition, so an extension author can add strategies for their own definitions.
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
title: testing.strategies
3+
---
4+
5+
::: zarr_metadata.testing.strategies
6+
options:
7+
inherited_members: false
8+
show_if_no_docstring: false

‎packages/zarr-metadata/mkdocs.yml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ nav:
2828
- '<code class="doc-symbol doc-symbol-toc doc-symbol-module"></code> <code>zarr_metadata.model</code>': api/model.md
2929
- '<code class="doc-symbol doc-symbol-toc doc-symbol-module"></code> <code>zarr_metadata.problems</code>': api/problems.md
3030
- '<code class="doc-symbol doc-symbol-toc doc-symbol-module"></code> <code>zarr_metadata.pydantic</code>': api/pydantic.md
31+
- '<code class="doc-symbol doc-symbol-toc doc-symbol-module"></code> <code>zarr_metadata.testing.strategies</code>': api/testing.md
3132
- '<code class="doc-symbol doc-symbol-toc doc-symbol-module"></code> <code>zarr_metadata.typed_json</code>': api/typed_json.md
3233
- '<code class="doc-symbol doc-symbol-toc doc-symbol-module"></code> <code>zarr_metadata.v2</code>': api/v2.md
3334
- '<code class="doc-symbol doc-symbol-toc doc-symbol-module"></code> <code>zarr_metadata.v3</code>':

‎packages/zarr-metadata/pyproject.toml‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,11 @@ dependencies = [
4343
"typing_extensions>=4.16",
4444
]
4545

46+
[project.optional-dependencies]
47+
# `zarr_metadata.testing.strategies`. 6.85: first release with
48+
# `characters(exclude_categories=...)`.
49+
testing = ["hypothesis>=6.85"]
50+
4651
[project.urls]
4752
Homepage = "https://github.com/zarr-developers/zarr-python"
4853
Source = "https://github.com/zarr-developers/zarr-python/tree/main/packages/zarr-metadata"
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
"""Testing utilities for code that reads or writes Zarr metadata.
2+
3+
`zarr_metadata.testing.strategies` holds Hypothesis strategies that draw
4+
valid metadata. It needs the `testing` extra:
5+
`pip install zarr-metadata[testing]`.
6+
"""
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
"""Strategies for each chunk grid this package defines.
2+
3+
Over an array of a known shape, a grid is drawn to fit it: a chunk
4+
length for each dimension, never zero ("Chunk sizes must be greater
5+
than zero", https://github.com/zarr-developers/zarr-specs/blob/fc7dd9c9beb5a50b87f9b08b00bf50fc0048482f/docs/v3/chunk-grids/regular-grid/index.rst#L40),
6+
and rectilinear edges that cover each dimension. Over no shape, what is
7+
drawn is what the grid's rules accept.
8+
"""
9+
10+
from __future__ import annotations
11+
12+
from typing import TYPE_CHECKING, Any, Final
13+
14+
from hypothesis import strategies as st
15+
16+
from zarr_metadata.testing._strategy import MAX_RANK, ChunkGridStrategy
17+
from zarr_metadata.v3.chunk_grid.rectilinear import RECTILINEAR_CHUNK_GRID
18+
from zarr_metadata.v3.chunk_grid.regular import REGULAR_CHUNK_GRID
19+
20+
if TYPE_CHECKING:
21+
from collections.abc import Mapping
22+
23+
from zarr_metadata._common import JSONValue
24+
from zarr_metadata.v3._definition import ChunkGridDefinition
25+
26+
_MAX_LENGTH: Final = 16
27+
"""The longest chunk drawn along a dimension whose length is unknown."""
28+
29+
_MAX_RUNS: Final = 5
30+
"""The most runs of equal lengths a rectilinear dimension is drawn with."""
31+
32+
_MAX_COUNT: Final = 4
33+
"""The most chunks a run is drawn with."""
34+
35+
36+
def _length(extent: int | None) -> st.SearchStrategy[int]:
37+
"""A chunk length along a dimension of `extent`: at least 1, and up to twice the extent when it is known and not 0."""
38+
if extent is None or extent == 0:
39+
return st.integers(1, _MAX_LENGTH)
40+
return st.integers(1, 2 * extent)
41+
42+
43+
def _regular(shape: tuple[int, ...] | None) -> st.SearchStrategy[Mapping[str, JSONValue]]:
44+
"""A chunk length for each dimension."""
45+
if shape is None:
46+
lengths = st.lists(_length(None), max_size=MAX_RANK).map(tuple)
47+
else:
48+
lengths = st.tuples(*(_length(extent) for extent in shape))
49+
return lengths.map(lambda chunk_shape: {"chunk_shape": chunk_shape})
50+
51+
52+
def _spelled_run(draw: st.DrawFn, size: int, count: int) -> list[JSONValue]:
53+
"""`count` chunks of `size`: one `[size, count]` pair, or the size written once for each."""
54+
if draw(st.booleans()):
55+
return [(size, count)]
56+
return [size] * count
57+
58+
59+
@st.composite
60+
def _edges(draw: st.DrawFn, extent: int | None) -> JSONValue:
61+
"""Edge lengths along a dimension, covering `extent`, in runs spelled as pairs or written out.
62+
63+
Runs are drawn apart, so two of one size can sit side by side and a
64+
pair can count one chunk: spellings the canonical form merges. A
65+
dimension of length zero, or of a length not known, may be covered by
66+
no edges at all.
67+
"""
68+
min_runs = 0 if extent is None or extent == 0 else 1
69+
runs = draw(
70+
st.lists(
71+
st.tuples(st.integers(1, _MAX_LENGTH), st.integers(1, _MAX_COUNT)),
72+
min_size=min_runs,
73+
max_size=_MAX_RUNS,
74+
)
75+
)
76+
covered = sum(size * count for size, count in runs)
77+
if extent is not None and covered < extent:
78+
runs.append((extent - covered, 1))
79+
spelled: list[JSONValue] = []
80+
for size, count in runs:
81+
spelled.extend(_spelled_run(draw, size, count))
82+
return tuple(spelled)
83+
84+
85+
def _rectilinear_dimension(extent: int | None) -> st.SearchStrategy[JSONValue]:
86+
"""A bare length, which repeats until it covers the dimension, or edges that cover it."""
87+
return _length(extent) | _edges(extent)
88+
89+
90+
def _rectilinear(shape: tuple[int, ...] | None) -> st.SearchStrategy[Mapping[str, JSONValue]]:
91+
"""Inline chunk shapes, one entry for each dimension."""
92+
if shape is None:
93+
dimensions = st.lists(_rectilinear_dimension(None), max_size=MAX_RANK).map(tuple)
94+
else:
95+
dimensions = st.tuples(*(_rectilinear_dimension(extent) for extent in shape))
96+
return dimensions.map(lambda chunk_shapes: {"kind": "inline", "chunk_shapes": chunk_shapes})
97+
98+
99+
CHUNK_GRID_STRATEGIES: Final[Mapping[ChunkGridDefinition[Any], ChunkGridStrategy]] = {
100+
REGULAR_CHUNK_GRID: ChunkGridStrategy(configurations=_regular),
101+
RECTILINEAR_CHUNK_GRID: ChunkGridStrategy(configurations=_rectilinear),
102+
}
103+
"""A strategy for each chunk grid."""
104+
105+
__all__ = ["CHUNK_GRID_STRATEGIES"]
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
"""Strategies for each chunk key encoding this package defines."""
2+
3+
from __future__ import annotations
4+
5+
from typing import TYPE_CHECKING, Any, Final
6+
7+
from hypothesis import strategies as st
8+
9+
from zarr_metadata.testing._strategy import ChunkKeyEncodingStrategy
10+
from zarr_metadata.v3.chunk_key_encoding.default import (
11+
DEFAULT_CHUNK_KEY_ENCODING,
12+
DEFAULT_CHUNK_KEY_ENCODING_SEPARATOR,
13+
)
14+
from zarr_metadata.v3.chunk_key_encoding.v2 import (
15+
V2_CHUNK_KEY_ENCODING,
16+
V2_CHUNK_KEY_ENCODING_SEPARATOR,
17+
)
18+
19+
if TYPE_CHECKING:
20+
from collections.abc import Mapping
21+
22+
from zarr_metadata.v3._definition import ChunkKeyEncodingDefinition
23+
24+
CHUNK_KEY_ENCODING_STRATEGIES: Final[
25+
Mapping[ChunkKeyEncodingDefinition[Any], ChunkKeyEncodingStrategy]
26+
] = {
27+
DEFAULT_CHUNK_KEY_ENCODING: ChunkKeyEncodingStrategy(
28+
configurations=st.fixed_dictionaries(
29+
{}, optional={"separator": st.sampled_from(DEFAULT_CHUNK_KEY_ENCODING_SEPARATOR)}
30+
)
31+
),
32+
V2_CHUNK_KEY_ENCODING: ChunkKeyEncodingStrategy(
33+
configurations=st.fixed_dictionaries(
34+
{}, optional={"separator": st.sampled_from(V2_CHUNK_KEY_ENCODING_SEPARATOR)}
35+
)
36+
),
37+
}
38+
"""A strategy for each chunk key encoding: a `separator`, or none, which means the encoding's default."""
39+
40+
__all__ = ["CHUNK_KEY_ENCODING_STRATEGIES"]
Lines changed: 179 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,179 @@
1+
"""Strategies for each codec this package defines that holds no other field.
2+
3+
A codec handed an array draws what fits the chunk: a `bytes` codec an
4+
`endian` for a type whose values take several bytes, a `transpose` an
5+
`order` with an entry for each axis. Handed `Chunk()`, nothing is known
6+
of the chunk, and what is drawn is what the codec's rules accept.
7+
"""
8+
9+
from __future__ import annotations
10+
11+
from typing import TYPE_CHECKING, Any, Final
12+
13+
from hypothesis import strategies as st
14+
15+
from zarr_metadata.definition._definition import AcceptedField
16+
from zarr_metadata.testing._data_type import (
17+
COMPLEX_WIDTHS,
18+
FLOAT_WIDTHS,
19+
INTEGER_RANGES,
20+
FloatWidth,
21+
finite_floats,
22+
float_spellings,
23+
)
24+
from zarr_metadata.testing._strategy import EMPTY_CONFIGURATIONS, MAX_RANK, CodecStrategy
25+
from zarr_metadata.v3._definition import Chunk, storage_of
26+
from zarr_metadata.v3.codec._arithmetic import NOT_NUMBERS
27+
from zarr_metadata.v3.codec.blosc import BLOSC_CNAME, BLOSC_CODEC, BLOSC_NO_SHUFFLE, BLOSC_SHUFFLE
28+
from zarr_metadata.v3.codec.bytes import BYTES_CODEC, ENDIANNESS
29+
from zarr_metadata.v3.codec.crc32c import CRC32C_CODEC
30+
from zarr_metadata.v3.codec.gzip import GZIP_CODEC
31+
from zarr_metadata.v3.codec.scale_offset import SCALE_OFFSET_CODEC
32+
from zarr_metadata.v3.codec.transpose import TRANSPOSE_CODEC
33+
from zarr_metadata.v3.codec.zstd import ZSTD_CODEC, ZSTD_MAX_LEVEL, ZSTD_MIN_LEVEL
34+
from zarr_metadata.v3.data_type.numpy_datetime64 import NUMPY_DATETIME64_DATA_TYPE
35+
from zarr_metadata.v3.data_type.numpy_timedelta64 import NUMPY_TIMEDELTA64_DATA_TYPE
36+
37+
if TYPE_CHECKING:
38+
from collections.abc import Mapping
39+
40+
from zarr_metadata._common import JSONValue
41+
from zarr_metadata.v3._definition import CodecDefinition
42+
43+
_BLOSC_MAX_TYPESIZE: Final = 255
44+
"""The widest element c-blosc takes: `BLOSC_MAX_TYPESIZE`."""
45+
46+
_BLOSC_MAX_BLOCKSIZE: Final = 2**31 - 1
47+
"""The largest block c-blosc takes, a signed 32-bit size; 0 lets it choose."""
48+
49+
_ENDIAN: Final = st.sampled_from(ENDIANNESS)
50+
51+
_NUMPY_TIMES: Final = frozenset({NUMPY_DATETIME64_DATA_TYPE, NUMPY_TIMEDELTA64_DATA_TYPE})
52+
"""The numpy time types, each stored as a signed 64-bit integer."""
53+
54+
_NUMPY_TIME_RANGE: Final = (-(2**63) + 1, 2**63 - 1)
55+
"""The signed 64-bit integers but the least, which numpy reads as `NaT`: the finite numpy times."""
56+
57+
58+
def _bytes(chunk: Chunk) -> st.SearchStrategy[Mapping[str, JSONValue]] | None:
59+
"""An `endian`, required for a data type whose values take several bytes; None for one whose values vary in size."""
60+
storage = None if chunk.data_type is None else storage_of(chunk.data_type)
61+
if storage == "variable_length":
62+
return None
63+
if storage == "multi_byte":
64+
return st.fixed_dictionaries({"endian": _ENDIAN})
65+
return st.fixed_dictionaries({}, optional={"endian": _ENDIAN})
66+
67+
68+
@st.composite
69+
def _blosc(draw: st.DrawFn) -> Mapping[str, JSONValue]:
70+
"""A compressor, a level, a shuffle and a block size; and a `typesize`, which only `noshuffle` may leave out.
71+
72+
Under `noshuffle` the spec says `typesize` "is ignored", so it is
73+
drawn there too, a spelling that is not the simplest.
74+
"""
75+
shuffle = draw(st.sampled_from(BLOSC_SHUFFLE))
76+
typesize = st.integers(1, _BLOSC_MAX_TYPESIZE)
77+
required: dict[str, st.SearchStrategy[JSONValue]] = {
78+
"cname": st.sampled_from(BLOSC_CNAME),
79+
"clevel": st.integers(0, 9),
80+
"shuffle": st.just(shuffle),
81+
"blocksize": st.integers(0, _BLOSC_MAX_BLOCKSIZE),
82+
}
83+
if shuffle == BLOSC_NO_SHUFFLE:
84+
return draw(st.fixed_dictionaries(required, optional={"typesize": typesize}))
85+
return draw(st.fixed_dictionaries({**required, "typesize": typesize}))
86+
87+
88+
def _order(rank: int) -> st.SearchStrategy[Mapping[str, JSONValue]]:
89+
return st.permutations(range(rank)).map(lambda order: {"order": tuple(order)})
90+
91+
92+
def _transpose(chunk: Chunk) -> st.SearchStrategy[Mapping[str, JSONValue]]:
93+
"""A permutation of the chunk's axes; of some number of axes, when the chunk does not say."""
94+
if chunk.rank is not None:
95+
return _order(chunk.rank)
96+
return st.integers(0, MAX_RANK).flatmap(_order)
97+
98+
99+
def _finite_float_values(width: FloatWidth) -> st.SearchStrategy[JSONValue]:
100+
"""A finite float of `width` bits, as a number or the hex string of its bits."""
101+
return finite_floats(width).flatmap(lambda value: float_spellings(value, width))
102+
103+
104+
def _non_zero_float_values(width: FloatWidth) -> st.SearchStrategy[JSONValue]:
105+
"""A finite, non-zero float of `width` bits, as a number or the hex string of its bits."""
106+
return (
107+
finite_floats(width)
108+
.filter(lambda value: value != 0)
109+
.flatmap(lambda value: float_spellings(value, width))
110+
)
111+
112+
113+
def _scale_offset(chunk: Chunk) -> st.SearchStrategy[Mapping[str, JSONValue]] | None:
114+
"""An `offset` and a `scale`, each a finite value of the data type the codec is handed, the scale not zero; None for a data type whose values are not numbers.
115+
116+
Each is a fill value of the chunk's data type
117+
(https://github.com/zarr-developers/zarr-extensions/blob/4da7b37a84f76e660902f6d3de3eaef0e0febae6/codecs/scale_offset/README.md?plain=1#L39-L43),
118+
a float's as a number or the hex string of its bits, a complex
119+
number's as a pair of them. Each is drawn finite, and the scale
120+
non-zero, so that decoding never divides by zero; a scale small
121+
enough that decoding overflows is still drawn. A numpy time is drawn
122+
as the signed 64-bit integer it is stored as, never `NaT`, since it
123+
"is compatible with any codec that supports arrays of signed 64-bit
124+
integers"
125+
(https://github.com/zarr-developers/zarr-extensions/blob/4da7b37a84f76e660902f6d3de3eaef0e0febae6/data-types/numpy.datetime64/README.md?plain=1#L120).
126+
A data type this package does not define, whose values it cannot
127+
draw, takes only the configuration with neither, the identity.
128+
Handed a chunk whose data type is unknown, the values are small
129+
non-negative integers, which every integer and float type holds.
130+
"""
131+
data_type = chunk.data_type
132+
definition = data_type.definition if isinstance(data_type, AcceptedField) else None
133+
if definition is None:
134+
offset: st.SearchStrategy[JSONValue] = st.integers(0, 127)
135+
scale: st.SearchStrategy[JSONValue] = st.integers(1, 127)
136+
elif definition.name in NOT_NUMBERS:
137+
return None
138+
elif definition in INTEGER_RANGES or definition in _NUMPY_TIMES:
139+
low, high = INTEGER_RANGES.get(definition, _NUMPY_TIME_RANGE)
140+
offset = st.integers(low, high)
141+
scale = st.integers(low, high).filter(lambda value: value != 0)
142+
elif definition in FLOAT_WIDTHS:
143+
offset = _finite_float_values(FLOAT_WIDTHS[definition])
144+
scale = _non_zero_float_values(FLOAT_WIDTHS[definition])
145+
elif definition in COMPLEX_WIDTHS:
146+
width = COMPLEX_WIDTHS[definition]
147+
offset = st.tuples(_finite_float_values(width), _finite_float_values(width))
148+
# Non-zero in either part is a non-zero complex number.
149+
scale = st.one_of(
150+
st.tuples(_non_zero_float_values(width), _finite_float_values(width)),
151+
st.tuples(_finite_float_values(width), _non_zero_float_values(width)),
152+
)
153+
else:
154+
return EMPTY_CONFIGURATIONS
155+
return st.fixed_dictionaries({}, optional={"offset": offset, "scale": scale})
156+
157+
158+
def _unchunked(configurations: st.SearchStrategy[Mapping[str, JSONValue]]) -> CodecStrategy:
159+
"""A codec whose configurations do not depend on the chunk it is handed."""
160+
return CodecStrategy(configurations=lambda _chunk: configurations)
161+
162+
163+
CODEC_STRATEGIES: Final[Mapping[CodecDefinition[Any], CodecStrategy]] = {
164+
BLOSC_CODEC: _unchunked(_blosc()),
165+
BYTES_CODEC: CodecStrategy(configurations=_bytes),
166+
CRC32C_CODEC: _unchunked(EMPTY_CONFIGURATIONS),
167+
GZIP_CODEC: _unchunked(st.fixed_dictionaries({"level": st.integers(0, 9)})),
168+
SCALE_OFFSET_CODEC: CodecStrategy(configurations=_scale_offset),
169+
TRANSPOSE_CODEC: CodecStrategy(configurations=_transpose),
170+
ZSTD_CODEC: _unchunked(
171+
st.fixed_dictionaries(
172+
{"level": st.integers(ZSTD_MIN_LEVEL, ZSTD_MAX_LEVEL)},
173+
optional={"checksum": st.booleans()},
174+
)
175+
),
176+
}
177+
"""A strategy for each codec that holds no other field."""
178+
179+
__all__ = ["CODEC_STRATEGIES"]

0 commit comments

Comments
 (0)