zarr_metadata.v3.codec
zarr_metadata.v3.codec ¶
Zarr v3 codec spec types.
Each codec defined by the spec or by zarr-extensions has its own submodule
(blosc, bytes, cast_value, crc32c, gzip, scale_offset,
sharding_indexed, transpose, zstd).
The <X>CodecMetadata aliases re-exported here are the canonical type for
each codec's permitted JSON shapes (object form plus, where the spec allows,
a bare-string short-hand form). For the underlying <X>CodecObject,
<X>CodecConfiguration, etc., import directly from the leaf submodule.
For the field-level "any codec entry" alias (used in array metadata's
codecs list and in sharding's inner pipelines), import ZarrV3MetadataFieldJSON
from zarr_metadata.v3.
Each codec's pipeline position (array -> array, array -> bytes,
bytes -> bytes) is the kind class its entity subclasses, in
zarr_metadata.v3.entity.
See https://zarr-specs.readthedocs.io/en/latest/v3/codecs/index.html
zarr_metadata.v3.codec.blosc ¶
Blosc codec types.
See https://zarr-specs.readthedocs.io/en/latest/v3/codecs/blosc/index.html
BLOSC_CNAME
module-attribute
¶
BLOSC_CNAME: Final = (
"lz4",
"lz4hc",
"blosclz",
"snappy",
"zlib",
"zstd",
)
Tuple of permitted values for the cname field of the blosc codec.
BLOSC_CODEC_NAME
module-attribute
¶
BLOSC_CODEC_NAME: Final = 'blosc'
The name field value of the blosc codec.
BLOSC_NO_SHUFFLE
module-attribute
¶
BLOSC_NO_SHUFFLE: Final = 'noshuffle'
The shuffle value under which typesize carries no information.
The spec requires typesize "unless shuffle is "noshuffle", in which
case the value is ignored", so this is the one value that changes whether
another member is required.
BLOSC_SHUFFLE
module-attribute
¶
BLOSC_SHUFFLE: Final = (
"noshuffle",
"shuffle",
"bitshuffle",
)
Tuple of permitted values for the shuffle field of the blosc codec.
BloscCName
module-attribute
¶
BloscCName = Literal[
"lz4", "lz4hc", "blosclz", "snappy", "zlib", "zstd"
]
Literal type of blosc compressor identifiers.
BloscCodecMetadata
module-attribute
¶
BloscCodecMetadata = BloscCodecObject
Permitted JSON shape for blosc codec metadata.
The configuration has multiple required keys (cname, clevel, shuffle,
blocksize), so only the object form is valid; the short-hand-name form
is not permitted by the spec for this codec.
https://github.com/zarr-developers/zarr-specs/blob/fc7dd9c9beb5a50b87f9b08b00bf50fc0048482f/docs/v3/codecs/blosc/index.rst#L57-L98 (configuration parameters)
https://github.com/zarr-developers/zarr-specs/blob/fc7dd9c9beb5a50b87f9b08b00bf50fc0048482f/docs/v3/core/index.rst#L1562-L1564 (short-hand names only "if no configuration metadata is required")
BloscCodecName
module-attribute
¶
BloscCodecName = Literal['blosc']
Literal type of the name field of the blosc codec.
BloscShuffle
module-attribute
¶
BloscShuffle = Literal["noshuffle", "shuffle", "bitshuffle"]
Literal type of blosc shuffle mode names.
__all__
module-attribute
¶
__all__ = [
"BLOSC_CNAME",
"BLOSC_CODEC_NAME",
"BLOSC_NO_SHUFFLE",
"BLOSC_SHUFFLE",
"BloscCName",
"BloscCodec",
"BloscCodecConfiguration",
"BloscCodecMetadata",
"BloscCodecName",
"BloscCodecObject",
"BloscOptions",
"BloscShuffle",
]
BloscCodec
dataclass
¶
Bases: BytesBytesCodec
The blosc codec, coerced from its metadata.
Everything blosc knows about itself: the shape its metadata takes, the values the spec allows in it, and the simplest spelling of an equivalent document.
Source code in src/zarr_metadata/v3/codec/blosc.py
configuration
instance-attribute
¶
configuration: BloscOptions
The record of this entity's members.
An entity with members narrows it to its own record, configuration:
GzipOptions, its one positional argument. An entity of a bare name
defaults it to the empty record -- configuration: Configuration =
field(default_factory=Configuration) -- so that Crc32cCodec()
builds; coerce passes the record either way.
identifier
class-attribute
¶
identifier: str = BLOSC_CODEC_NAME
The name this entity is registered under.
Usually the name the metadata carries. The raw-bytes data types are
the exception: every r<N> spelling is one family, so the family gets
an invented identifier that no real name can collide with.
variable_size
class-attribute
¶
variable_size: bool = True
Whether this codec's output size depends on the bytes it is given.
A compressor's does, so a shard index encoded with one has no size derivable from metadata alone, and the shard cannot be read. Every codec says, because a default in either direction is a verdict.
__post_init__ ¶
Refuse a record that is not this entity's own, then the first problem the rules find.
The runtime half of the entity's type, as the record's constructor
is of the record's: GzipCodec(BloscOptions(...)) and a family
member carrying a name that is not a string are refused before
any rule reads them. Then BloscCodec(BloscOptions(clevel=99))
raises on the first problem the rules yield.
Source code in src/zarr_metadata/v3/_entity.py
accepts
classmethod
¶
Whether name denotes this entity.
Constant for all but the raw-bytes family, where one class covers
every r<N>.
canonical ¶
canonical() -> Self
Without a typesize that noshuffle renders meaningless.
The spec says of that case that "the value is ignored", so two documents differing only there describe the same codec.
Source code in src/zarr_metadata/v3/codec/blosc.py
coerce
classmethod
¶
value as this entity, or the reasons it is not one: the class's validation routine.
resolve relates a field's name to this class and hands it the
field, refined JSON with arrays as tuples, which is what value
is; this is what the class does with it. The configuration is
parsed against the record the configuration field names,
member by member; a member holding another entity is read in
context, the scope this reading is happening in. An optional
member the document left out is UNSET in the record, so no
field's default decides what a document said. The entity is
built only when every member of its own read -- its rules are
written over a whole configuration -- and handed back only when
everything inside it read too.
The envelope is the field's, not the class's, and resolve
judges it: a stray member or a must_understand of false is
not reported here. Called on a class no scope has registered,
this runs with none of registration's refusals having happened.
Source code in src/zarr_metadata/v3/_entity.py
create_unchecked
classmethod
¶
This entity with these fields, built without the constructor's checks.
The one way around them, for a caller that has just made them:
coerce, which type-checked the record and ran the rules before
building. Every field is given -- the record, and the carried
name for a family -- since nothing here applies a default.
Anything that has not checked goes through the constructor.
Source code in src/zarr_metadata/v3/_entity.py
incoming_problems ¶
incoming_problems(
incoming: ArrayParts | None,
) -> tuple[ValidationProblem, ...]
Why this codec cannot be applied to the array that reaches it.
incoming is None once the chain can no longer say what reaches
here, and the default answer to that is nothing: declining beats
guessing. Locations are relative to this codec's configuration;
an empty one lands on the codec itself.
Source code in src/zarr_metadata/v3/_entity.py
inner_pipelines ¶
inner_pipelines(
incoming: ArrayParts | None,
) -> Mapping[
str,
tuple[
Sequence[CodecEntity | Opaque], ArrayParts | None
],
]
The pipelines this codec holds, by the member holding each, with what each is handed.
A shard holds two: its codecs, handed its inner chunk, and its
index_codecs, handed the shard index. Refinement walks them as
it walks the pipeline this codec stands in, locating what it
finds under the member, so a codec that holds pipelines says
which and what they receive, and judges nothing inside them
itself. Default: none.
Source code in src/zarr_metadata/v3/_entity.py
name_problems
classmethod
¶
name_problems(name: str) -> Iterator[ValidationProblem]
Why name, which accepts claimed, is not a well-formed name of this family.
For a family, whose names carry data -- r<N> -- and which claims
a malformed member so that it is reported rather than waved
through as an unknown extension. Locations are relative to the
entity: (). Default: none, for an entity of one name.
Source code in src/zarr_metadata/v3/_entity.py
to_json ¶
to_json() -> ZarrV3MetadataFieldJSON
This entity as a document would write it.
Written from the configuration record by the same declaration
coerce reads it by, each member by the writer its annotation
implies: the bare name when every member it holds is absent, the
object otherwise, a contained entity through its own to_json,
a JSON-valued member copied so the document is not a handle on
the entity. Faithful to every member: read a document, write it
back, and those come out as they went in. The envelope is
written the entity's way -- the bare name when nothing is
configured, the object otherwise, no must_understand, which
means what absence means -- because an entity alone has no
document to be faithful to; ArrayDocumentV3.to_json puts back
the spelling the document used. Ask canonical first if you
want the simplest equivalent spelling.
An entity whose JSON is not its fields overrides this; none in the package does.
Source code in src/zarr_metadata/v3/_entity.py
with_configuration ¶
This entity with these configuration members changed.
codec.with_configuration(typesize=UNSET) is the record rebuilt
through its constructor, which refuses a member of the wrong
type, and the entity rebuilt through its own, which refuses a
value the rules disallow -- the same checks as any construction,
since pyright cannot see the members through **changes. A
name that is not a member is refused the way replace refuses
it.
Source code in src/zarr_metadata/v3/_entity.py
BloscCodecConfiguration ¶
Bases: TypedDict
Configuration for the Zarr v3 blosc codec.
Source code in src/zarr_metadata/v3/codec/blosc.py
BloscCodecObject ¶
Bases: TypedDict
blosc codec metadata in object form.
Source code in src/zarr_metadata/v3/codec/blosc.py
BloscOptions
dataclass
¶
Bases: Configuration
What blosc is configured with.
Source code in src/zarr_metadata/v3/codec/blosc.py
__init__ ¶
__init__(
cname: BloscCName,
clevel: int,
shuffle: BloscShuffle,
blocksize: int,
typesize: int | UNSET = UNSET,
) -> None
__post_init__ ¶
Refuse every member of the wrong type, so GzipOptions(level="high") raises.
create_unchecked
classmethod
¶
This record with these members, built without the constructor's check.
The one way around the check, for a caller that has just made
it: the parser, which type-checked every member against the same
annotations before building the record. Every field is given --
the parser gives an absent optional member as UNSET -- since
nothing here applies a default. Anything that has not checked
the members goes through the constructor.
Source code in src/zarr_metadata/v3/_entity.py
problems ¶
problems() -> Iterator[ValidationProblem]
Bounds on clevel and blocksize; typesize against shuffle.
Under noshuffle the spec says of typesize that "the value is
ignored", and canonical drops it; under either shuffle it is
required, and positive.
Source code in src/zarr_metadata/v3/codec/blosc.py
zarr_metadata.v3.codec.bytes ¶
Bytes codec types.
See https://zarr-specs.readthedocs.io/en/latest/v3/codecs/bytes/index.html
BYTES_CODEC_NAME
module-attribute
¶
BYTES_CODEC_NAME: Final = 'bytes'
The name field value of the bytes codec.
BytesCodecMetadata
module-attribute
¶
BytesCodecMetadata = BytesCodecObject | BytesCodecName
Permitted JSON shapes for bytes codec metadata.
The configuration has no required keys (endian is conditionally required
at runtime based on data type), so the spec's short-hand-name form is
permitted in addition to the object form, and the object form may itself
omit configuration entirely.
https://github.com/zarr-developers/zarr-specs/blob/fc7dd9c9beb5a50b87f9b08b00bf50fc0048482f/docs/v3/codecs/bytes/index.rst#L64-L69 ("endian: Required for data types for which endianness is applicable")
https://github.com/zarr-developers/zarr-specs/blob/fc7dd9c9beb5a50b87f9b08b00bf50fc0048482f/docs/v3/core/index.rst#L1562-L1564
BytesCodecName
module-attribute
¶
BytesCodecName = Literal['bytes']
Literal type of the name field of the bytes codec.
ENDIANNESS
module-attribute
¶
ENDIANNESS: Final = ('little', 'big')
Tuple of permitted values for the endian field of the bytes codec.
Endianness
module-attribute
¶
Endianness = Literal['little', 'big']
Literal type of byte order of multi-byte numeric data.
__all__
module-attribute
¶
__all__ = [
"BYTES_CODEC_NAME",
"ENDIANNESS",
"BytesCodec",
"BytesCodecConfiguration",
"BytesCodecMetadata",
"BytesCodecName",
"BytesCodecObject",
"BytesOptions",
"Endianness",
]
BytesCodec
dataclass
¶
Bases: ArrayBytesCodec
The bytes codec, coerced from its metadata.
endian is optional and absent means something: a one-byte data type
has no byte order to state, and the spec lets such an array omit it.
Source code in src/zarr_metadata/v3/codec/bytes.py
configuration
instance-attribute
¶
configuration: BytesOptions
The record of this entity's members.
An entity with members narrows it to its own record, configuration:
GzipOptions, its one positional argument. An entity of a bare name
defaults it to the empty record -- configuration: Configuration =
field(default_factory=Configuration) -- so that Crc32cCodec()
builds; coerce passes the record either way.
identifier
class-attribute
¶
identifier: str = BYTES_CODEC_NAME
The name this entity is registered under.
Usually the name the metadata carries. The raw-bytes data types are
the exception: every r<N> spelling is one family, so the family gets
an invented identifier that no real name can collide with.
variable_size
class-attribute
¶
variable_size: bool = False
Whether this codec's output size depends on the bytes it is given.
A compressor's does, so a shard index encoded with one has no size derivable from metadata alone, and the shard cannot be read. Every codec says, because a default in either direction is a verdict.
__post_init__ ¶
Refuse a record that is not this entity's own, then the first problem the rules find.
The runtime half of the entity's type, as the record's constructor
is of the record's: GzipCodec(BloscOptions(...)) and a family
member carrying a name that is not a string are refused before
any rule reads them. Then BloscCodec(BloscOptions(clevel=99))
raises on the first problem the rules yield.
Source code in src/zarr_metadata/v3/_entity.py
accepts
classmethod
¶
Whether name denotes this entity.
Constant for all but the raw-bytes family, where one class covers
every r<N>.
canonical ¶
canonical() -> Self
This entity in the simplest form that means the same thing.
A transformation, asked for by canonicalize_array_metadata_v3
and by nothing else. to_json does not apply it, because writing
a document back is not the same as asking for it to be rewritten:
a reader that reads and writes should not change bytes it was not
asked to change.
The default is the entity itself. Override it where two spellings
of the entity's members mean the same -- a rectilinear
dimension's run-length encoding, a typesize that noshuffle
ignores -- and, in an entity that contains entities, to put those
in canonical form: self.with_configuration(inner=self.inner.canonical()).
Source code in src/zarr_metadata/v3/_entity.py
coerce
classmethod
¶
value as this entity, or the reasons it is not one: the class's validation routine.
resolve relates a field's name to this class and hands it the
field, refined JSON with arrays as tuples, which is what value
is; this is what the class does with it. The configuration is
parsed against the record the configuration field names,
member by member; a member holding another entity is read in
context, the scope this reading is happening in. An optional
member the document left out is UNSET in the record, so no
field's default decides what a document said. The entity is
built only when every member of its own read -- its rules are
written over a whole configuration -- and handed back only when
everything inside it read too.
The envelope is the field's, not the class's, and resolve
judges it: a stray member or a must_understand of false is
not reported here. Called on a class no scope has registered,
this runs with none of registration's refusals having happened.
Source code in src/zarr_metadata/v3/_entity.py
create_unchecked
classmethod
¶
This entity with these fields, built without the constructor's checks.
The one way around them, for a caller that has just made them:
coerce, which type-checked the record and ran the rules before
building. Every field is given -- the record, and the carried
name for a family -- since nothing here applies a default.
Anything that has not checked goes through the constructor.
Source code in src/zarr_metadata/v3/_entity.py
incoming_problems ¶
incoming_problems(
incoming: ArrayParts | None,
) -> tuple[ValidationProblem, ...]
The data type reaching here must have a raw byte representation.
A variable-length type has no fixed one, so this codec cannot
encode it. A multi-byte one has several orderings, so endian is
required -- and the message names the type, because inside a
shard's index_codecs the array is the shard index, whose
uint64 type appears nowhere in the document.
Source code in src/zarr_metadata/v3/codec/bytes.py
inner_pipelines ¶
inner_pipelines(
incoming: ArrayParts | None,
) -> Mapping[
str,
tuple[
Sequence[CodecEntity | Opaque], ArrayParts | None
],
]
The pipelines this codec holds, by the member holding each, with what each is handed.
A shard holds two: its codecs, handed its inner chunk, and its
index_codecs, handed the shard index. Refinement walks them as
it walks the pipeline this codec stands in, locating what it
finds under the member, so a codec that holds pipelines says
which and what they receive, and judges nothing inside them
itself. Default: none.
Source code in src/zarr_metadata/v3/_entity.py
name_problems
classmethod
¶
name_problems(name: str) -> Iterator[ValidationProblem]
Why name, which accepts claimed, is not a well-formed name of this family.
For a family, whose names carry data -- r<N> -- and which claims
a malformed member so that it is reported rather than waved
through as an unknown extension. Locations are relative to the
entity: (). Default: none, for an entity of one name.
Source code in src/zarr_metadata/v3/_entity.py
to_json ¶
to_json() -> ZarrV3MetadataFieldJSON
This entity as a document would write it.
Written from the configuration record by the same declaration
coerce reads it by, each member by the writer its annotation
implies: the bare name when every member it holds is absent, the
object otherwise, a contained entity through its own to_json,
a JSON-valued member copied so the document is not a handle on
the entity. Faithful to every member: read a document, write it
back, and those come out as they went in. The envelope is
written the entity's way -- the bare name when nothing is
configured, the object otherwise, no must_understand, which
means what absence means -- because an entity alone has no
document to be faithful to; ArrayDocumentV3.to_json puts back
the spelling the document used. Ask canonical first if you
want the simplest equivalent spelling.
An entity whose JSON is not its fields overrides this; none in the package does.
Source code in src/zarr_metadata/v3/_entity.py
with_configuration ¶
This entity with these configuration members changed.
codec.with_configuration(typesize=UNSET) is the record rebuilt
through its constructor, which refuses a member of the wrong
type, and the entity rebuilt through its own, which refuses a
value the rules disallow -- the same checks as any construction,
since pyright cannot see the members through **changes. A
name that is not a member is refused the way replace refuses
it.
Source code in src/zarr_metadata/v3/_entity.py
BytesCodecConfiguration ¶
Bases: TypedDict
Configuration for the Zarr v3 bytes codec.
The endian field is required for multi-byte data types.
Source code in src/zarr_metadata/v3/codec/bytes.py
BytesCodecObject ¶
Bases: TypedDict
bytes codec metadata in object form.
configuration is itself optional — when no configuration fields are
set, the entire configuration key may be omitted. This matches the
bare-string short-hand form (BytesCodecName) at the canonical data
level; both encodings describe a bytes codec with default settings.
Source code in src/zarr_metadata/v3/codec/bytes.py
BytesOptions
dataclass
¶
Bases: Configuration
What bytes is configured with.
Source code in src/zarr_metadata/v3/codec/bytes.py
__post_init__ ¶
Refuse every member of the wrong type, so GzipOptions(level="high") raises.
create_unchecked
classmethod
¶
This record with these members, built without the constructor's check.
The one way around the check, for a caller that has just made
it: the parser, which type-checked every member against the same
annotations before building the record. Every field is given --
the parser gives an absent optional member as UNSET -- since
nothing here applies a default. Anything that has not checked
the members goes through the constructor.
Source code in src/zarr_metadata/v3/_entity.py
problems ¶
problems() -> Iterator[ValidationProblem]
zarr_metadata.v3.codec.cast_value ¶
Cast-value codec types.
See https://github.com/zarr-developers/zarr-extensions/blob/4da7b37a84f76e660902f6d3de3eaef0e0febae6/codecs/cast_value/README.md
CAST_OUT_OF_RANGE_MODE
module-attribute
¶
CAST_OUT_OF_RANGE_MODE: Final = ('clamp', 'wrap')
Tuple of permitted values for the out_of_range field of the cast_value codec.
CAST_ROUNDING_MODE
module-attribute
¶
CAST_ROUNDING_MODE: Final = (
"nearest-even",
"towards-zero",
"towards-positive",
"towards-negative",
"nearest-away",
)
Tuple of permitted values for the rounding field of the cast_value codec.
CAST_VALUE_CODEC_NAME
module-attribute
¶
CAST_VALUE_CODEC_NAME: Final = 'cast_value'
The name field value of the cast_value codec.
CastOutOfRangeMode
module-attribute
¶
CastOutOfRangeMode = Literal['clamp', 'wrap']
Literal type of permitted values for the out_of_range configuration field.
If absent, out-of-range values are an encoding/decoding error.
CastRoundingMode
module-attribute
¶
CastRoundingMode = Literal[
"nearest-even",
"towards-zero",
"towards-positive",
"towards-negative",
"nearest-away",
]
Literal type of permitted values for the rounding configuration field.
Defaults to "nearest-even" if absent.
CastValueCodecMetadata
module-attribute
¶
CastValueCodecMetadata = CastValueCodecObject
Permitted JSON shape for cast_value codec metadata.
configuration.data_type is required, so only the object form is valid;
the short-hand-name form is not permitted by the spec for this codec.
https://github.com/zarr-developers/zarr-extensions/blob/4da7b37a84f76e660902f6d3de3eaef0e0febae6/codecs/cast_value/README.md#L33-L36 and #L46-L48 (required fields)
https://github.com/zarr-developers/zarr-specs/blob/fc7dd9c9beb5a50b87f9b08b00bf50fc0048482f/docs/v3/core/index.rst#L1562-L1564 (short-hand names only "if no configuration metadata is required")
CastValueCodecName
module-attribute
¶
CastValueCodecName = Literal['cast_value']
Literal type of the name field of the cast_value codec.
SCALAR_MAP_KEYS
module-attribute
¶
SCALAR_MAP_KEYS: Final = ('encode', 'decode')
The two directions a scalar_map can override, both optional.
ScalarMapEntry
module-attribute
¶
A single [input, output] mapping in a scalar_map direction.
Each scalar is JSON-encoded per its data type's fill-value rules (so
e.g. "NaN" and "+Infinity" are permitted).
__all__
module-attribute
¶
__all__ = [
"CAST_OUT_OF_RANGE_MODE",
"CAST_ROUNDING_MODE",
"CAST_VALUE_CODEC_NAME",
"SCALAR_MAP_KEYS",
"CastOutOfRangeMode",
"CastRoundingMode",
"CastValueCodec",
"CastValueCodecConfiguration",
"CastValueCodecMetadata",
"CastValueCodecName",
"CastValueCodecObject",
"CastValueOptions",
"ScalarMap",
"ScalarMapEntry",
]
CastValueCodec
dataclass
¶
Bases: ArrayArrayCodec
The cast_value codec, coerced from its metadata.
Holds the data type it casts to, so like sharding_indexed it is
read in a scope rather than on its own.
Source code in src/zarr_metadata/v3/codec/cast_value.py
configuration
instance-attribute
¶
configuration: CastValueOptions
The record of this entity's members.
An entity with members narrows it to its own record, configuration:
GzipOptions, its one positional argument. An entity of a bare name
defaults it to the empty record -- configuration: Configuration =
field(default_factory=Configuration) -- so that Crc32cCodec()
builds; coerce passes the record either way.
identifier
class-attribute
¶
identifier: str = CAST_VALUE_CODEC_NAME
The name this entity is registered under.
Usually the name the metadata carries. The raw-bytes data types are
the exception: every r<N> spelling is one family, so the family gets
an invented identifier that no real name can collide with.
variable_size
class-attribute
¶
variable_size: bool = False
Whether this codec's output size depends on the bytes it is given.
A compressor's does, so a shard index encoded with one has no size derivable from metadata alone, and the shard cannot be read. Every codec says, because a default in either direction is a verdict.
__post_init__ ¶
Refuse a record that is not this entity's own, then the first problem the rules find.
The runtime half of the entity's type, as the record's constructor
is of the record's: GzipCodec(BloscOptions(...)) and a family
member carrying a name that is not a string are refused before
any rule reads them. Then BloscCodec(BloscOptions(clevel=99))
raises on the first problem the rules yield.
Source code in src/zarr_metadata/v3/_entity.py
accepts
classmethod
¶
Whether name denotes this entity.
Constant for all but the raw-bytes family, where one class covers
every r<N>.
coerce
classmethod
¶
value as this entity, or the reasons it is not one: the class's validation routine.
resolve relates a field's name to this class and hands it the
field, refined JSON with arrays as tuples, which is what value
is; this is what the class does with it. The configuration is
parsed against the record the configuration field names,
member by member; a member holding another entity is read in
context, the scope this reading is happening in. An optional
member the document left out is UNSET in the record, so no
field's default decides what a document said. The entity is
built only when every member of its own read -- its rules are
written over a whole configuration -- and handed back only when
everything inside it read too.
The envelope is the field's, not the class's, and resolve
judges it: a stray member or a must_understand of false is
not reported here. Called on a class no scope has registered,
this runs with none of registration's refusals having happened.
Source code in src/zarr_metadata/v3/_entity.py
create_unchecked
classmethod
¶
This entity with these fields, built without the constructor's checks.
The one way around them, for a caller that has just made them:
coerce, which type-checked the record and ran the rules before
building. Every field is given -- the record, and the carried
name for a family -- since nothing here applies a default.
Anything that has not checked goes through the constructor.
Source code in src/zarr_metadata/v3/_entity.py
incoming_problems ¶
incoming_problems(
incoming: ArrayParts | None,
) -> tuple[ValidationProblem, ...]
Why this codec cannot be applied to the array that reaches it.
incoming is None once the chain can no longer say what reaches
here, and the default answer to that is nothing: declining beats
guessing. Locations are relative to this codec's configuration;
an empty one lands on the codec itself.
Source code in src/zarr_metadata/v3/_entity.py
inner_pipelines ¶
inner_pipelines(
incoming: ArrayParts | None,
) -> Mapping[
str,
tuple[
Sequence[CodecEntity | Opaque], ArrayParts | None
],
]
The pipelines this codec holds, by the member holding each, with what each is handed.
A shard holds two: its codecs, handed its inner chunk, and its
index_codecs, handed the shard index. Refinement walks them as
it walks the pipeline this codec stands in, locating what it
finds under the member, so a codec that holds pipelines says
which and what they receive, and judges nothing inside them
itself. Default: none.
Source code in src/zarr_metadata/v3/_entity.py
name_problems
classmethod
¶
name_problems(name: str) -> Iterator[ValidationProblem]
Why name, which accepts claimed, is not a well-formed name of this family.
For a family, whose names carry data -- r<N> -- and which claims
a malformed member so that it is reported rather than waved
through as an unknown extension. Locations are relative to the
entity: (). Default: none, for an entity of one name.
Source code in src/zarr_metadata/v3/_entity.py
to_json ¶
to_json() -> ZarrV3MetadataFieldJSON
This entity as a document would write it.
Written from the configuration record by the same declaration
coerce reads it by, each member by the writer its annotation
implies: the bare name when every member it holds is absent, the
object otherwise, a contained entity through its own to_json,
a JSON-valued member copied so the document is not a handle on
the entity. Faithful to every member: read a document, write it
back, and those come out as they went in. The envelope is
written the entity's way -- the bare name when nothing is
configured, the object otherwise, no must_understand, which
means what absence means -- because an entity alone has no
document to be faithful to; ArrayDocumentV3.to_json puts back
the spelling the document used. Ask canonical first if you
want the simplest equivalent spelling.
An entity whose JSON is not its fields overrides this; none in the package does.
Source code in src/zarr_metadata/v3/_entity.py
transition ¶
transition(incoming: ArrayParts) -> ArrayParts | None
The same parts, holding the type this codec casts to.
Source code in src/zarr_metadata/v3/codec/cast_value.py
with_configuration ¶
This entity with these configuration members changed.
codec.with_configuration(typesize=UNSET) is the record rebuilt
through its constructor, which refuses a member of the wrong
type, and the entity rebuilt through its own, which refuses a
value the rules disallow -- the same checks as any construction,
since pyright cannot see the members through **changes. A
name that is not a member is refused the way replace refuses
it.
Source code in src/zarr_metadata/v3/_entity.py
CastValueCodecConfiguration ¶
Bases: TypedDict
Configuration for the Zarr v3 cast_value codec.
data_type is the target data type that input values are cast to. It
is the same shape as the top-level array data_type field: either a
bare-string primitive name or a {name, configuration} envelope.
Source code in src/zarr_metadata/v3/codec/cast_value.py
CastValueCodecObject ¶
Bases: TypedDict
cast_value codec metadata in object form.
Source code in src/zarr_metadata/v3/codec/cast_value.py
CastValueOptions
dataclass
¶
Bases: Configuration
What cast_value is configured with.
Source code in src/zarr_metadata/v3/codec/cast_value.py
__init__ ¶
__init__(
data_type: DataTypeEntity | Opaque,
rounding: CastRoundingMode | UNSET = UNSET,
out_of_range: CastOutOfRangeMode | UNSET = UNSET,
scalar_map: ScalarMap | UNSET = UNSET,
) -> None
__post_init__ ¶
Refuse every member of the wrong type, so GzipOptions(level="high") raises.
create_unchecked
classmethod
¶
This record with these members, built without the constructor's check.
The one way around the check, for a caller that has just made
it: the parser, which type-checked every member against the same
annotations before building the record. Every field is given --
the parser gives an absent optional member as UNSET -- since
nothing here applies a default. Anything that has not checked
the members goes through the constructor.
Source code in src/zarr_metadata/v3/_entity.py
problems ¶
problems() -> Iterator[ValidationProblem]
ScalarMap ¶
Bases: TypedDict
Optional encode/decode scalar overrides for the cast_value codec.
Source code in src/zarr_metadata/v3/codec/cast_value.py
zarr_metadata.v3.codec.crc32c ¶
CRC32C codec types.
See https://zarr-specs.readthedocs.io/en/latest/v3/codecs/crc32c/index.html
The CRC32C codec has no configuration fields, so the configuration
key is absent from the metadata.
CRC32C_CODEC_NAME
module-attribute
¶
CRC32C_CODEC_NAME: Final = 'crc32c'
The name field value of the crc32c codec.
Crc32cCodecMetadata
module-attribute
¶
Crc32cCodecMetadata = Crc32cCodecObject | Crc32cCodecName
Permitted JSON shapes for crc32c codec metadata.
The spec's Extension definition allows extensions with no required configuration to be encoded as a bare short-hand name. CRC32C has no configuration, so both forms are valid. https://github.com/zarr-developers/zarr-specs/blob/fc7dd9c9beb5a50b87f9b08b00bf50fc0048482f/docs/v3/core/index.rst#L1562-L1564
Crc32cCodecName
module-attribute
¶
Crc32cCodecName = Literal['crc32c']
Literal type of the name field of the crc32c codec.
__all__
module-attribute
¶
__all__ = [
"CRC32C_CODEC_NAME",
"Crc32cCodec",
"Crc32cCodecMetadata",
"Crc32cCodecName",
"Crc32cCodecObject",
]
Crc32cCodec
dataclass
¶
Bases: BytesBytesCodec
The crc32c codec, coerced from its metadata.
The name says everything: a checksum has nothing to configure.
Source code in src/zarr_metadata/v3/codec/crc32c.py
configuration
class-attribute
instance-attribute
¶
configuration: Configuration = field(
default_factory=Configuration
)
The record of this entity's members.
An entity with members narrows it to its own record, configuration:
GzipOptions, its one positional argument. An entity of a bare name
defaults it to the empty record -- configuration: Configuration =
field(default_factory=Configuration) -- so that Crc32cCodec()
builds; coerce passes the record either way.
identifier
class-attribute
¶
identifier: str = CRC32C_CODEC_NAME
The name this entity is registered under.
Usually the name the metadata carries. The raw-bytes data types are
the exception: every r<N> spelling is one family, so the family gets
an invented identifier that no real name can collide with.
variable_size
class-attribute
¶
variable_size: bool = False
Whether this codec's output size depends on the bytes it is given.
A compressor's does, so a shard index encoded with one has no size derivable from metadata alone, and the shard cannot be read. Every codec says, because a default in either direction is a verdict.
__post_init__ ¶
Refuse a record that is not this entity's own, then the first problem the rules find.
The runtime half of the entity's type, as the record's constructor
is of the record's: GzipCodec(BloscOptions(...)) and a family
member carrying a name that is not a string are refused before
any rule reads them. Then BloscCodec(BloscOptions(clevel=99))
raises on the first problem the rules yield.
Source code in src/zarr_metadata/v3/_entity.py
accepts
classmethod
¶
Whether name denotes this entity.
Constant for all but the raw-bytes family, where one class covers
every r<N>.
canonical ¶
canonical() -> Self
This entity in the simplest form that means the same thing.
A transformation, asked for by canonicalize_array_metadata_v3
and by nothing else. to_json does not apply it, because writing
a document back is not the same as asking for it to be rewritten:
a reader that reads and writes should not change bytes it was not
asked to change.
The default is the entity itself. Override it where two spellings
of the entity's members mean the same -- a rectilinear
dimension's run-length encoding, a typesize that noshuffle
ignores -- and, in an entity that contains entities, to put those
in canonical form: self.with_configuration(inner=self.inner.canonical()).
Source code in src/zarr_metadata/v3/_entity.py
coerce
classmethod
¶
value as this entity, or the reasons it is not one: the class's validation routine.
resolve relates a field's name to this class and hands it the
field, refined JSON with arrays as tuples, which is what value
is; this is what the class does with it. The configuration is
parsed against the record the configuration field names,
member by member; a member holding another entity is read in
context, the scope this reading is happening in. An optional
member the document left out is UNSET in the record, so no
field's default decides what a document said. The entity is
built only when every member of its own read -- its rules are
written over a whole configuration -- and handed back only when
everything inside it read too.
The envelope is the field's, not the class's, and resolve
judges it: a stray member or a must_understand of false is
not reported here. Called on a class no scope has registered,
this runs with none of registration's refusals having happened.
Source code in src/zarr_metadata/v3/_entity.py
create_unchecked
classmethod
¶
This entity with these fields, built without the constructor's checks.
The one way around them, for a caller that has just made them:
coerce, which type-checked the record and ran the rules before
building. Every field is given -- the record, and the carried
name for a family -- since nothing here applies a default.
Anything that has not checked goes through the constructor.
Source code in src/zarr_metadata/v3/_entity.py
incoming_problems ¶
incoming_problems(
incoming: ArrayParts | None,
) -> tuple[ValidationProblem, ...]
Why this codec cannot be applied to the array that reaches it.
incoming is None once the chain can no longer say what reaches
here, and the default answer to that is nothing: declining beats
guessing. Locations are relative to this codec's configuration;
an empty one lands on the codec itself.
Source code in src/zarr_metadata/v3/_entity.py
inner_pipelines ¶
inner_pipelines(
incoming: ArrayParts | None,
) -> Mapping[
str,
tuple[
Sequence[CodecEntity | Opaque], ArrayParts | None
],
]
The pipelines this codec holds, by the member holding each, with what each is handed.
A shard holds two: its codecs, handed its inner chunk, and its
index_codecs, handed the shard index. Refinement walks them as
it walks the pipeline this codec stands in, locating what it
finds under the member, so a codec that holds pipelines says
which and what they receive, and judges nothing inside them
itself. Default: none.
Source code in src/zarr_metadata/v3/_entity.py
name_problems
classmethod
¶
name_problems(name: str) -> Iterator[ValidationProblem]
Why name, which accepts claimed, is not a well-formed name of this family.
For a family, whose names carry data -- r<N> -- and which claims
a malformed member so that it is reported rather than waved
through as an unknown extension. Locations are relative to the
entity: (). Default: none, for an entity of one name.
Source code in src/zarr_metadata/v3/_entity.py
to_json ¶
to_json() -> ZarrV3MetadataFieldJSON
This entity as a document would write it.
Written from the configuration record by the same declaration
coerce reads it by, each member by the writer its annotation
implies: the bare name when every member it holds is absent, the
object otherwise, a contained entity through its own to_json,
a JSON-valued member copied so the document is not a handle on
the entity. Faithful to every member: read a document, write it
back, and those come out as they went in. The envelope is
written the entity's way -- the bare name when nothing is
configured, the object otherwise, no must_understand, which
means what absence means -- because an entity alone has no
document to be faithful to; ArrayDocumentV3.to_json puts back
the spelling the document used. Ask canonical first if you
want the simplest equivalent spelling.
An entity whose JSON is not its fields overrides this; none in the package does.
Source code in src/zarr_metadata/v3/_entity.py
with_configuration ¶
This entity with these configuration members changed.
codec.with_configuration(typesize=UNSET) is the record rebuilt
through its constructor, which refuses a member of the wrong
type, and the entity rebuilt through its own, which refuses a
value the rules disallow -- the same checks as any construction,
since pyright cannot see the members through **changes. A
name that is not a member is refused the way replace refuses
it.
Source code in src/zarr_metadata/v3/_entity.py
Crc32cCodecObject ¶
Bases: TypedDict
crc32c codec metadata in object form.
Per spec the codec has no configuration fields. configuration is
optional and, if present, should be an empty mapping.
https://github.com/zarr-developers/zarr-specs/blob/fc7dd9c9beb5a50b87f9b08b00bf50fc0048482f/docs/v3/codecs/crc32c/index.rst#L63-L66
Source code in src/zarr_metadata/v3/codec/crc32c.py
zarr_metadata.v3.codec.gzip ¶
Gzip codec types.
See https://zarr-specs.readthedocs.io/en/latest/v3/codecs/gzip/index.html
GZIP_CODEC_NAME
module-attribute
¶
GZIP_CODEC_NAME: Final = 'gzip'
The name field value of the gzip codec.
GzipCodecMetadata
module-attribute
¶
GzipCodecMetadata = GzipCodecObject
Permitted JSON shape for gzip codec metadata.
configuration.level is required (it determines the codec's output bytes
and is therefore part of the metadata's reproducibility contract), so
only the object form is valid; the short-hand-name form is not permitted.
GzipCodecName
module-attribute
¶
GzipCodecName = Literal['gzip']
Literal type of the name field of the gzip codec.
__all__
module-attribute
¶
__all__ = [
"GZIP_CODEC_NAME",
"GzipCodec",
"GzipCodecConfiguration",
"GzipCodecMetadata",
"GzipCodecName",
"GzipCodecObject",
"GzipOptions",
]
GzipCodec
dataclass
¶
Bases: BytesBytesCodec
The gzip codec, coerced from its metadata.
Source code in src/zarr_metadata/v3/codec/gzip.py
configuration
instance-attribute
¶
configuration: GzipOptions
The record of this entity's members.
An entity with members narrows it to its own record, configuration:
GzipOptions, its one positional argument. An entity of a bare name
defaults it to the empty record -- configuration: Configuration =
field(default_factory=Configuration) -- so that Crc32cCodec()
builds; coerce passes the record either way.
identifier
class-attribute
¶
identifier: str = GZIP_CODEC_NAME
The name this entity is registered under.
Usually the name the metadata carries. The raw-bytes data types are
the exception: every r<N> spelling is one family, so the family gets
an invented identifier that no real name can collide with.
variable_size
class-attribute
¶
variable_size: bool = True
Whether this codec's output size depends on the bytes it is given.
A compressor's does, so a shard index encoded with one has no size derivable from metadata alone, and the shard cannot be read. Every codec says, because a default in either direction is a verdict.
__post_init__ ¶
Refuse a record that is not this entity's own, then the first problem the rules find.
The runtime half of the entity's type, as the record's constructor
is of the record's: GzipCodec(BloscOptions(...)) and a family
member carrying a name that is not a string are refused before
any rule reads them. Then BloscCodec(BloscOptions(clevel=99))
raises on the first problem the rules yield.
Source code in src/zarr_metadata/v3/_entity.py
accepts
classmethod
¶
Whether name denotes this entity.
Constant for all but the raw-bytes family, where one class covers
every r<N>.
canonical ¶
canonical() -> Self
This entity in the simplest form that means the same thing.
A transformation, asked for by canonicalize_array_metadata_v3
and by nothing else. to_json does not apply it, because writing
a document back is not the same as asking for it to be rewritten:
a reader that reads and writes should not change bytes it was not
asked to change.
The default is the entity itself. Override it where two spellings
of the entity's members mean the same -- a rectilinear
dimension's run-length encoding, a typesize that noshuffle
ignores -- and, in an entity that contains entities, to put those
in canonical form: self.with_configuration(inner=self.inner.canonical()).
Source code in src/zarr_metadata/v3/_entity.py
coerce
classmethod
¶
value as this entity, or the reasons it is not one: the class's validation routine.
resolve relates a field's name to this class and hands it the
field, refined JSON with arrays as tuples, which is what value
is; this is what the class does with it. The configuration is
parsed against the record the configuration field names,
member by member; a member holding another entity is read in
context, the scope this reading is happening in. An optional
member the document left out is UNSET in the record, so no
field's default decides what a document said. The entity is
built only when every member of its own read -- its rules are
written over a whole configuration -- and handed back only when
everything inside it read too.
The envelope is the field's, not the class's, and resolve
judges it: a stray member or a must_understand of false is
not reported here. Called on a class no scope has registered,
this runs with none of registration's refusals having happened.
Source code in src/zarr_metadata/v3/_entity.py
create_unchecked
classmethod
¶
This entity with these fields, built without the constructor's checks.
The one way around them, for a caller that has just made them:
coerce, which type-checked the record and ran the rules before
building. Every field is given -- the record, and the carried
name for a family -- since nothing here applies a default.
Anything that has not checked goes through the constructor.
Source code in src/zarr_metadata/v3/_entity.py
incoming_problems ¶
incoming_problems(
incoming: ArrayParts | None,
) -> tuple[ValidationProblem, ...]
Why this codec cannot be applied to the array that reaches it.
incoming is None once the chain can no longer say what reaches
here, and the default answer to that is nothing: declining beats
guessing. Locations are relative to this codec's configuration;
an empty one lands on the codec itself.
Source code in src/zarr_metadata/v3/_entity.py
inner_pipelines ¶
inner_pipelines(
incoming: ArrayParts | None,
) -> Mapping[
str,
tuple[
Sequence[CodecEntity | Opaque], ArrayParts | None
],
]
The pipelines this codec holds, by the member holding each, with what each is handed.
A shard holds two: its codecs, handed its inner chunk, and its
index_codecs, handed the shard index. Refinement walks them as
it walks the pipeline this codec stands in, locating what it
finds under the member, so a codec that holds pipelines says
which and what they receive, and judges nothing inside them
itself. Default: none.
Source code in src/zarr_metadata/v3/_entity.py
name_problems
classmethod
¶
name_problems(name: str) -> Iterator[ValidationProblem]
Why name, which accepts claimed, is not a well-formed name of this family.
For a family, whose names carry data -- r<N> -- and which claims
a malformed member so that it is reported rather than waved
through as an unknown extension. Locations are relative to the
entity: (). Default: none, for an entity of one name.
Source code in src/zarr_metadata/v3/_entity.py
to_json ¶
to_json() -> ZarrV3MetadataFieldJSON
This entity as a document would write it.
Written from the configuration record by the same declaration
coerce reads it by, each member by the writer its annotation
implies: the bare name when every member it holds is absent, the
object otherwise, a contained entity through its own to_json,
a JSON-valued member copied so the document is not a handle on
the entity. Faithful to every member: read a document, write it
back, and those come out as they went in. The envelope is
written the entity's way -- the bare name when nothing is
configured, the object otherwise, no must_understand, which
means what absence means -- because an entity alone has no
document to be faithful to; ArrayDocumentV3.to_json puts back
the spelling the document used. Ask canonical first if you
want the simplest equivalent spelling.
An entity whose JSON is not its fields overrides this; none in the package does.
Source code in src/zarr_metadata/v3/_entity.py
with_configuration ¶
This entity with these configuration members changed.
codec.with_configuration(typesize=UNSET) is the record rebuilt
through its constructor, which refuses a member of the wrong
type, and the entity rebuilt through its own, which refuses a
value the rules disallow -- the same checks as any construction,
since pyright cannot see the members through **changes. A
name that is not a member is refused the way replace refuses
it.
Source code in src/zarr_metadata/v3/_entity.py
GzipCodecConfiguration ¶
Bases: TypedDict
Configuration for the Zarr v3 gzip codec.
level is an integer in the range 0-9; 0 disables compression and 9
is slowest with the best compression ratio. The codec's compressed
output depends on level, so metadata that omits it cannot
reproducibly identify the chunk bytes produced by a writer — level
is required for the metadata to fulfill its reproducibility role,
even though the spec text does not mark it required with RFC 2119
keywords.
https://github.com/zarr-developers/zarr-specs/blob/fc7dd9c9beb5a50b87f9b08b00bf50fc0048482f/docs/v3/codecs/gzip/index.rst#L57-L66
Source code in src/zarr_metadata/v3/codec/gzip.py
GzipCodecObject ¶
Bases: TypedDict
gzip codec metadata in object form.
Source code in src/zarr_metadata/v3/codec/gzip.py
GzipOptions
dataclass
¶
Bases: Configuration
What gzip is configured with.
Source code in src/zarr_metadata/v3/codec/gzip.py
__post_init__ ¶
Refuse every member of the wrong type, so GzipOptions(level="high") raises.
create_unchecked
classmethod
¶
This record with these members, built without the constructor's check.
The one way around the check, for a caller that has just made
it: the parser, which type-checked every member against the same
annotations before building the record. Every field is given --
the parser gives an absent optional member as UNSET -- since
nothing here applies a default. Anything that has not checked
the members goes through the constructor.
Source code in src/zarr_metadata/v3/_entity.py
problems ¶
problems() -> Iterator[ValidationProblem]
Every reason these values are not allowed, yielded as found. Default: none.
zarr_metadata.v3.codec.scale_offset ¶
Scale-offset codec types.
See https://github.com/zarr-developers/zarr-extensions/blob/4da7b37a84f76e660902f6d3de3eaef0e0febae6/codecs/scale_offset/README.md
SCALE_OFFSET_CODEC_NAME
module-attribute
¶
SCALE_OFFSET_CODEC_NAME: Final = 'scale_offset'
The name field value of the scale_offset codec.
ScaleOffsetCodecMetadata
module-attribute
¶
ScaleOffsetCodecMetadata = (
ScaleOffsetCodecObject | ScaleOffsetCodecName
)
Permitted JSON shapes for scale_offset codec metadata.
The configuration has no required keys (both offset and scale are
optional, and the configuration itself is optional), so the short-hand-name
form is permitted in addition to the object form.
ScaleOffsetCodecName
module-attribute
¶
ScaleOffsetCodecName = Literal['scale_offset']
Literal type of the name field of the scale_offset codec.
__all__
module-attribute
¶
__all__ = [
"SCALE_OFFSET_CODEC_NAME",
"ScaleOffsetCodec",
"ScaleOffsetCodecConfiguration",
"ScaleOffsetCodecMetadata",
"ScaleOffsetCodecName",
"ScaleOffsetCodecObject",
"ScaleOffsetOptions",
]
ScaleOffsetCodec
dataclass
¶
Bases: ArrayArrayCodec
The scale_offset codec, coerced from its metadata.
Both members are optional and any JSON scalar is well-typed here; what
a given value means depends on the data type it is applied to, which
incoming_problems asks of the type that reaches the codec.
Source code in src/zarr_metadata/v3/codec/scale_offset.py
configuration
instance-attribute
¶
configuration: ScaleOffsetOptions
The record of this entity's members.
An entity with members narrows it to its own record, configuration:
GzipOptions, its one positional argument. An entity of a bare name
defaults it to the empty record -- configuration: Configuration =
field(default_factory=Configuration) -- so that Crc32cCodec()
builds; coerce passes the record either way.
identifier
class-attribute
¶
identifier: str = SCALE_OFFSET_CODEC_NAME
The name this entity is registered under.
Usually the name the metadata carries. The raw-bytes data types are
the exception: every r<N> spelling is one family, so the family gets
an invented identifier that no real name can collide with.
variable_size
class-attribute
¶
variable_size: bool = False
Whether this codec's output size depends on the bytes it is given.
A compressor's does, so a shard index encoded with one has no size derivable from metadata alone, and the shard cannot be read. Every codec says, because a default in either direction is a verdict.
__post_init__ ¶
Refuse a record that is not this entity's own, then the first problem the rules find.
The runtime half of the entity's type, as the record's constructor
is of the record's: GzipCodec(BloscOptions(...)) and a family
member carrying a name that is not a string are refused before
any rule reads them. Then BloscCodec(BloscOptions(clevel=99))
raises on the first problem the rules yield.
Source code in src/zarr_metadata/v3/_entity.py
accepts
classmethod
¶
Whether name denotes this entity.
Constant for all but the raw-bytes family, where one class covers
every r<N>.
canonical ¶
canonical() -> Self
This entity in the simplest form that means the same thing.
A transformation, asked for by canonicalize_array_metadata_v3
and by nothing else. to_json does not apply it, because writing
a document back is not the same as asking for it to be rewritten:
a reader that reads and writes should not change bytes it was not
asked to change.
The default is the entity itself. Override it where two spellings
of the entity's members mean the same -- a rectilinear
dimension's run-length encoding, a typesize that noshuffle
ignores -- and, in an entity that contains entities, to put those
in canonical form: self.with_configuration(inner=self.inner.canonical()).
Source code in src/zarr_metadata/v3/_entity.py
coerce
classmethod
¶
value as this entity, or the reasons it is not one: the class's validation routine.
resolve relates a field's name to this class and hands it the
field, refined JSON with arrays as tuples, which is what value
is; this is what the class does with it. The configuration is
parsed against the record the configuration field names,
member by member; a member holding another entity is read in
context, the scope this reading is happening in. An optional
member the document left out is UNSET in the record, so no
field's default decides what a document said. The entity is
built only when every member of its own read -- its rules are
written over a whole configuration -- and handed back only when
everything inside it read too.
The envelope is the field's, not the class's, and resolve
judges it: a stray member or a must_understand of false is
not reported here. Called on a class no scope has registered,
this runs with none of registration's refusals having happened.
Source code in src/zarr_metadata/v3/_entity.py
create_unchecked
classmethod
¶
This entity with these fields, built without the constructor's checks.
The one way around them, for a caller that has just made them:
coerce, which type-checked the record and ran the rules before
building. Every field is given -- the record, and the carried
name for a family -- since nothing here applies a default.
Anything that has not checked goes through the constructor.
Source code in src/zarr_metadata/v3/_entity.py
incoming_problems ¶
incoming_problems(
incoming: ArrayParts | None,
) -> tuple[ValidationProblem, ...]
What the array handed to this codec must be, and what its members must be for it.
The registry defines the codec for data types with arithmetic and
lists the integer and floating-point ones. offset and scale
are each "encoded to JSON using the Zarr V3 fill value encoding
for the input array's data type" -- the type that reaches this
codec, which after a cast_value is not the array's own -- so
each is a fill value of that type, and that type judges it: the
string "0" is no float32 and no int32.
Source code in src/zarr_metadata/v3/codec/scale_offset.py
inner_pipelines ¶
inner_pipelines(
incoming: ArrayParts | None,
) -> Mapping[
str,
tuple[
Sequence[CodecEntity | Opaque], ArrayParts | None
],
]
The pipelines this codec holds, by the member holding each, with what each is handed.
A shard holds two: its codecs, handed its inner chunk, and its
index_codecs, handed the shard index. Refinement walks them as
it walks the pipeline this codec stands in, locating what it
finds under the member, so a codec that holds pipelines says
which and what they receive, and judges nothing inside them
itself. Default: none.
Source code in src/zarr_metadata/v3/_entity.py
name_problems
classmethod
¶
name_problems(name: str) -> Iterator[ValidationProblem]
Why name, which accepts claimed, is not a well-formed name of this family.
For a family, whose names carry data -- r<N> -- and which claims
a malformed member so that it is reported rather than waved
through as an unknown extension. Locations are relative to the
entity: (). Default: none, for an entity of one name.
Source code in src/zarr_metadata/v3/_entity.py
to_json ¶
to_json() -> ZarrV3MetadataFieldJSON
This entity as a document would write it.
Written from the configuration record by the same declaration
coerce reads it by, each member by the writer its annotation
implies: the bare name when every member it holds is absent, the
object otherwise, a contained entity through its own to_json,
a JSON-valued member copied so the document is not a handle on
the entity. Faithful to every member: read a document, write it
back, and those come out as they went in. The envelope is
written the entity's way -- the bare name when nothing is
configured, the object otherwise, no must_understand, which
means what absence means -- because an entity alone has no
document to be faithful to; ArrayDocumentV3.to_json puts back
the spelling the document used. Ask canonical first if you
want the simplest equivalent spelling.
An entity whose JSON is not its fields overrides this; none in the package does.
Source code in src/zarr_metadata/v3/_entity.py
transition ¶
transition(incoming: ArrayParts) -> ArrayParts | None
The same array, element for element.
The registry entry removed the astype field, so this codec no
longer changes the element type -- only the values.
Source code in src/zarr_metadata/v3/codec/scale_offset.py
with_configuration ¶
This entity with these configuration members changed.
codec.with_configuration(typesize=UNSET) is the record rebuilt
through its constructor, which refuses a member of the wrong
type, and the entity rebuilt through its own, which refuses a
value the rules disallow -- the same checks as any construction,
since pyright cannot see the members through **changes. A
name that is not a member is refused the way replace refuses
it.
Source code in src/zarr_metadata/v3/_entity.py
ScaleOffsetCodecConfiguration ¶
Bases: TypedDict
Configuration for the Zarr v3 scale_offset codec.
Both fields are optional. A missing offset is the additive identity
(e.g. 0 for numeric types); a missing scale is the multiplicative
identity (e.g. 1). Each scalar is JSON-encoded per the input array's
fill-value rules, so "NaN" and "+Infinity" style strings are
permitted in addition to numbers.
Source code in src/zarr_metadata/v3/codec/scale_offset.py
ScaleOffsetCodecObject ¶
Bases: TypedDict
scale_offset codec metadata in object form.
configuration is itself optional per spec — when both offset and
scale are at their identity defaults, the codec is a no-op and the
entire configuration field may be omitted.
https://github.com/zarr-developers/zarr-extensions/blob/4da7b37a84f76e660902f6d3de3eaef0e0febae6/codecs/scale_offset/README.md#L18 and #L35
Source code in src/zarr_metadata/v3/codec/scale_offset.py
ScaleOffsetOptions
dataclass
¶
Bases: Configuration
What scale_offset is configured with.
Source code in src/zarr_metadata/v3/codec/scale_offset.py
__post_init__ ¶
Refuse every member of the wrong type, so GzipOptions(level="high") raises.
create_unchecked
classmethod
¶
This record with these members, built without the constructor's check.
The one way around the check, for a caller that has just made
it: the parser, which type-checked every member against the same
annotations before building the record. Every field is given --
the parser gives an absent optional member as UNSET -- since
nothing here applies a default. Anything that has not checked
the members goes through the constructor.
Source code in src/zarr_metadata/v3/_entity.py
problems ¶
problems() -> Iterator[ValidationProblem]
Each value is a scalar of the array's type, so neither is null.
The registry says each is "JSON-encoded per the input array's
fill-value rules", and no data type admits null as a fill value.
Which scalar it should be needs the data type, so that part is the
document's question, not this codec's.
Source code in src/zarr_metadata/v3/codec/scale_offset.py
zarr_metadata.v3.codec.sharding_indexed ¶
Sharding-indexed codec types.
See https://zarr-specs.readthedocs.io/en/latest/v3/codecs/sharding-indexed/index.html
SHARDING_INDEXED_CODEC_NAME
module-attribute
¶
SHARDING_INDEXED_CODEC_NAME: Final = 'sharding_indexed'
The name field value of the sharding_indexed codec.
SHARDING_INDEX_LOCATION
module-attribute
¶
SHARDING_INDEX_LOCATION: Final = ('start', 'end')
Tuple of permitted values for the index_location field of the sharding_indexed codec.
ShardingIndexLocation
module-attribute
¶
ShardingIndexLocation = Literal['start', 'end']
Literal type of the position of the shard index within the encoded shard.
ShardingIndexedCodecMetadata
module-attribute
¶
ShardingIndexedCodecMetadata = ShardingIndexedCodecObject
Permitted JSON shape for sharding_indexed codec metadata.
The configuration has multiple required keys (chunk_shape, codecs,
index_codecs), so only the object form is valid; the short-hand-name
form is not permitted by the spec for this codec.
https://github.com/zarr-developers/zarr-specs/blob/fc7dd9c9beb5a50b87f9b08b00bf50fc0048482f/docs/v3/codecs/sharding-indexed/index.rst#L141-L155 (required members)
https://github.com/zarr-developers/zarr-specs/blob/fc7dd9c9beb5a50b87f9b08b00bf50fc0048482f/docs/v3/core/index.rst#L1562-L1564 (short-hand names only "if no configuration metadata is required")
ShardingIndexedCodecName
module-attribute
¶
ShardingIndexedCodecName = Literal['sharding_indexed']
Literal type of the name field of the sharding_indexed codec.
__all__
module-attribute
¶
__all__ = [
"SHARDING_INDEXED_CODEC_NAME",
"SHARDING_INDEX_LOCATION",
"ShardingIndexLocation",
"ShardingIndexedCodec",
"ShardingIndexedCodecConfiguration",
"ShardingIndexedCodecMetadata",
"ShardingIndexedCodecName",
"ShardingIndexedCodecObject",
"ShardingIndexedOptions",
]
ShardingIndexedCodec
dataclass
¶
Bases: ArrayBytesCodec
The sharding_indexed codec, coerced from its metadata.
Holds two codec pipelines, so it is one of the few entities that needs the scope it is being read in: an entry of either pipeline is itself an entity, read the same way this one was.
Source code in src/zarr_metadata/v3/codec/sharding_indexed.py
120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 | |
configuration
instance-attribute
¶
configuration: ShardingIndexedOptions
The record of this entity's members.
An entity with members narrows it to its own record, configuration:
GzipOptions, its one positional argument. An entity of a bare name
defaults it to the empty record -- configuration: Configuration =
field(default_factory=Configuration) -- so that Crc32cCodec()
builds; coerce passes the record either way.
identifier
class-attribute
¶
identifier: str = SHARDING_INDEXED_CODEC_NAME
The name this entity is registered under.
Usually the name the metadata carries. The raw-bytes data types are
the exception: every r<N> spelling is one family, so the family gets
an invented identifier that no real name can collide with.
variable_size
class-attribute
¶
variable_size: bool = True
Whether this codec's output size depends on the bytes it is given.
A compressor's does, so a shard index encoded with one has no size derivable from metadata alone, and the shard cannot be read. Every codec says, because a default in either direction is a verdict.
__post_init__ ¶
Refuse a record that is not this entity's own, then the first problem the rules find.
The runtime half of the entity's type, as the record's constructor
is of the record's: GzipCodec(BloscOptions(...)) and a family
member carrying a name that is not a string are refused before
any rule reads them. Then BloscCodec(BloscOptions(clevel=99))
raises on the first problem the rules yield.
Source code in src/zarr_metadata/v3/_entity.py
accepts
classmethod
¶
Whether name denotes this entity.
Constant for all but the raw-bytes family, where one class covers
every r<N>.
canonical ¶
canonical() -> Self
Each pipeline's codecs in their own canonical form.
Source code in src/zarr_metadata/v3/codec/sharding_indexed.py
coerce
classmethod
¶
value as this entity, or the reasons it is not one: the class's validation routine.
resolve relates a field's name to this class and hands it the
field, refined JSON with arrays as tuples, which is what value
is; this is what the class does with it. The configuration is
parsed against the record the configuration field names,
member by member; a member holding another entity is read in
context, the scope this reading is happening in. An optional
member the document left out is UNSET in the record, so no
field's default decides what a document said. The entity is
built only when every member of its own read -- its rules are
written over a whole configuration -- and handed back only when
everything inside it read too.
The envelope is the field's, not the class's, and resolve
judges it: a stray member or a must_understand of false is
not reported here. Called on a class no scope has registered,
this runs with none of registration's refusals having happened.
Source code in src/zarr_metadata/v3/_entity.py
create_unchecked
classmethod
¶
This entity with these fields, built without the constructor's checks.
The one way around them, for a caller that has just made them:
coerce, which type-checked the record and ran the rules before
building. Every field is given -- the record, and the carried
name for a family -- since nothing here applies a default.
Anything that has not checked goes through the constructor.
Source code in src/zarr_metadata/v3/_entity.py
incoming_problems ¶
incoming_problems(
incoming: ArrayParts | None,
) -> tuple[ValidationProblem, ...]
This shard against the array reaching it.
One sharding configuration encodes every chunk, so its inner
shape has to divide all of them. Under a rectilinear grid an axis
has several lengths and the inner extent must divide each; an axis
whose lengths are unknown declines while the others are judged.
The index must be readable from metadata alone, so no codec of
variable output size may encode it. The two pipelines are
inner_pipelines, refined by the walk.
Source code in src/zarr_metadata/v3/codec/sharding_indexed.py
inner_pipelines ¶
inner_pipelines(
incoming: ArrayParts | None,
) -> Mapping[
str,
tuple[
Sequence[CodecEntity | Opaque], ArrayParts | None
],
]
The inner chunk pipeline and the index pipeline, with what each is handed.
Both start from this codec's own configuration and from the
spec, so neither waits on what reached the codec. An unreadable
codec upstream costs the element type and the enclosing extents;
it does not make the inner chunk shape unknown, and the index is
a uint64 array whatever precedes it.
Source code in src/zarr_metadata/v3/codec/sharding_indexed.py
name_problems
classmethod
¶
name_problems(name: str) -> Iterator[ValidationProblem]
Why name, which accepts claimed, is not a well-formed name of this family.
For a family, whose names carry data -- r<N> -- and which claims
a malformed member so that it is reported rather than waved
through as an unknown extension. Locations are relative to the
entity: (). Default: none, for an entity of one name.
Source code in src/zarr_metadata/v3/_entity.py
to_json ¶
to_json() -> ZarrV3MetadataFieldJSON
This entity as a document would write it.
Written from the configuration record by the same declaration
coerce reads it by, each member by the writer its annotation
implies: the bare name when every member it holds is absent, the
object otherwise, a contained entity through its own to_json,
a JSON-valued member copied so the document is not a handle on
the entity. Faithful to every member: read a document, write it
back, and those come out as they went in. The envelope is
written the entity's way -- the bare name when nothing is
configured, the object otherwise, no must_understand, which
means what absence means -- because an entity alone has no
document to be faithful to; ArrayDocumentV3.to_json puts back
the spelling the document used. Ask canonical first if you
want the simplest equivalent spelling.
An entity whose JSON is not its fields overrides this; none in the package does.
Source code in src/zarr_metadata/v3/_entity.py
with_configuration ¶
This entity with these configuration members changed.
codec.with_configuration(typesize=UNSET) is the record rebuilt
through its constructor, which refuses a member of the wrong
type, and the entity rebuilt through its own, which refuses a
value the rules disallow -- the same checks as any construction,
since pyright cannot see the members through **changes. A
name that is not a member is refused the way replace refuses
it.
Source code in src/zarr_metadata/v3/_entity.py
ShardingIndexedCodecConfiguration ¶
Bases: TypedDict
Configuration for the Zarr v3 sharding_indexed codec.
chunk_shape is the shape of inner chunks along each dimension;
it must evenly divide the shard shape.
codecs is the codec pipeline applied to each inner chunk; exactly
one array-to-bytes codec is required.
index_codecs is the codec pipeline applied to the shard index;
it must be deterministic (no variable-size compression).
https://github.com/zarr-developers/zarr-specs/blob/fc7dd9c9beb5a50b87f9b08b00bf50fc0048482f/docs/v3/codecs/sharding-indexed/index.rst#L147-L155
index_location defaults to "end" per the spec.
https://github.com/zarr-developers/zarr-specs/blob/fc7dd9c9beb5a50b87f9b08b00bf50fc0048482f/docs/v3/codecs/sharding-indexed/index.rst#L157-L161
Source code in src/zarr_metadata/v3/codec/sharding_indexed.py
ShardingIndexedCodecObject ¶
Bases: TypedDict
sharding_indexed codec metadata in object form.
Source code in src/zarr_metadata/v3/codec/sharding_indexed.py
ShardingIndexedOptions
dataclass
¶
Bases: Configuration
What sharding_indexed is configured with.
Source code in src/zarr_metadata/v3/codec/sharding_indexed.py
index_location
class-attribute
instance-attribute
¶
index_location: ShardingIndexLocation | UNSET = UNSET
__init__ ¶
__init__(
chunk_shape: tuple[int, ...],
codecs: tuple[CodecEntity | Opaque, ...],
index_codecs: tuple[CodecEntity | Opaque, ...],
index_location: ShardingIndexLocation | UNSET = UNSET,
) -> None
__post_init__ ¶
Refuse every member of the wrong type, so GzipOptions(level="high") raises.
create_unchecked
classmethod
¶
This record with these members, built without the constructor's check.
The one way around the check, for a caller that has just made
it: the parser, which type-checked every member against the same
annotations before building the record. Every field is given --
the parser gives an absent optional member as UNSET -- since
nothing here applies a default. Anything that has not checked
the members goes through the constructor.
Source code in src/zarr_metadata/v3/_entity.py
problems ¶
problems() -> Iterator[ValidationProblem]
Every reason these values are not allowed, yielded as found. Default: none.
Source code in src/zarr_metadata/v3/codec/sharding_indexed.py
zarr_metadata.v3.codec.transpose ¶
Transpose codec types.
See https://zarr-specs.readthedocs.io/en/latest/v3/codecs/transpose/index.html
TRANSPOSE_CODEC_NAME
module-attribute
¶
TRANSPOSE_CODEC_NAME: Final = 'transpose'
The name field value of the transpose codec.
TransposeCodecMetadata
module-attribute
¶
TransposeCodecMetadata = TransposeCodecObject
Permitted JSON shape for transpose codec metadata.
order is required, so only the object form is valid; the short-hand-name
form is not permitted by the spec for this codec.
https://github.com/zarr-developers/zarr-specs/blob/fc7dd9c9beb5a50b87f9b08b00bf50fc0048482f/docs/v3/codecs/transpose/index.rst#L60-L66 ("order: Required")
https://github.com/zarr-developers/zarr-specs/blob/fc7dd9c9beb5a50b87f9b08b00bf50fc0048482f/docs/v3/core/index.rst#L1562-L1564 (short-hand names only "if no configuration metadata is required")
TransposeCodecName
module-attribute
¶
TransposeCodecName = Literal['transpose']
Literal type of the name field of the transpose codec.
__all__
module-attribute
¶
__all__ = [
"TRANSPOSE_CODEC_NAME",
"TransposeCodec",
"TransposeCodecConfiguration",
"TransposeCodecMetadata",
"TransposeCodecName",
"TransposeCodecObject",
"TransposeOptions",
]
TransposeCodec
dataclass
¶
Bases: ArrayArrayCodec
The transpose codec, coerced from its metadata.
Source code in src/zarr_metadata/v3/codec/transpose.py
configuration
instance-attribute
¶
configuration: TransposeOptions
The record of this entity's members.
An entity with members narrows it to its own record, configuration:
GzipOptions, its one positional argument. An entity of a bare name
defaults it to the empty record -- configuration: Configuration =
field(default_factory=Configuration) -- so that Crc32cCodec()
builds; coerce passes the record either way.
identifier
class-attribute
¶
identifier: str = TRANSPOSE_CODEC_NAME
The name this entity is registered under.
Usually the name the metadata carries. The raw-bytes data types are
the exception: every r<N> spelling is one family, so the family gets
an invented identifier that no real name can collide with.
variable_size
class-attribute
¶
variable_size: bool = False
Whether this codec's output size depends on the bytes it is given.
A compressor's does, so a shard index encoded with one has no size derivable from metadata alone, and the shard cannot be read. Every codec says, because a default in either direction is a verdict.
__post_init__ ¶
Refuse a record that is not this entity's own, then the first problem the rules find.
The runtime half of the entity's type, as the record's constructor
is of the record's: GzipCodec(BloscOptions(...)) and a family
member carrying a name that is not a string are refused before
any rule reads them. Then BloscCodec(BloscOptions(clevel=99))
raises on the first problem the rules yield.
Source code in src/zarr_metadata/v3/_entity.py
accepts
classmethod
¶
Whether name denotes this entity.
Constant for all but the raw-bytes family, where one class covers
every r<N>.
canonical ¶
canonical() -> Self
This entity in the simplest form that means the same thing.
A transformation, asked for by canonicalize_array_metadata_v3
and by nothing else. to_json does not apply it, because writing
a document back is not the same as asking for it to be rewritten:
a reader that reads and writes should not change bytes it was not
asked to change.
The default is the entity itself. Override it where two spellings
of the entity's members mean the same -- a rectilinear
dimension's run-length encoding, a typesize that noshuffle
ignores -- and, in an entity that contains entities, to put those
in canonical form: self.with_configuration(inner=self.inner.canonical()).
Source code in src/zarr_metadata/v3/_entity.py
coerce
classmethod
¶
value as this entity, or the reasons it is not one: the class's validation routine.
resolve relates a field's name to this class and hands it the
field, refined JSON with arrays as tuples, which is what value
is; this is what the class does with it. The configuration is
parsed against the record the configuration field names,
member by member; a member holding another entity is read in
context, the scope this reading is happening in. An optional
member the document left out is UNSET in the record, so no
field's default decides what a document said. The entity is
built only when every member of its own read -- its rules are
written over a whole configuration -- and handed back only when
everything inside it read too.
The envelope is the field's, not the class's, and resolve
judges it: a stray member or a must_understand of false is
not reported here. Called on a class no scope has registered,
this runs with none of registration's refusals having happened.
Source code in src/zarr_metadata/v3/_entity.py
create_unchecked
classmethod
¶
This entity with these fields, built without the constructor's checks.
The one way around them, for a caller that has just made them:
coerce, which type-checked the record and ran the rules before
building. Every field is given -- the record, and the carried
name for a family -- since nothing here applies a default.
Anything that has not checked goes through the constructor.
Source code in src/zarr_metadata/v3/_entity.py
incoming_problems ¶
incoming_problems(
incoming: ArrayParts | None,
) -> tuple[ValidationProblem, ...]
A transpose permutes the array it receives, so ranks must agree.
Judged against what actually reaches this codec: inside a shard that is the inner chunk, and after another transpose it is that transpose's output.
Source code in src/zarr_metadata/v3/codec/transpose.py
inner_pipelines ¶
inner_pipelines(
incoming: ArrayParts | None,
) -> Mapping[
str,
tuple[
Sequence[CodecEntity | Opaque], ArrayParts | None
],
]
The pipelines this codec holds, by the member holding each, with what each is handed.
A shard holds two: its codecs, handed its inner chunk, and its
index_codecs, handed the shard index. Refinement walks them as
it walks the pipeline this codec stands in, locating what it
finds under the member, so a codec that holds pipelines says
which and what they receive, and judges nothing inside them
itself. Default: none.
Source code in src/zarr_metadata/v3/_entity.py
name_problems
classmethod
¶
name_problems(name: str) -> Iterator[ValidationProblem]
Why name, which accepts claimed, is not a well-formed name of this family.
For a family, whose names carry data -- r<N> -- and which claims
a malformed member so that it is reported rather than waved
through as an unknown extension. Locations are relative to the
entity: (). Default: none, for an entity of one name.
Source code in src/zarr_metadata/v3/_entity.py
to_json ¶
to_json() -> ZarrV3MetadataFieldJSON
This entity as a document would write it.
Written from the configuration record by the same declaration
coerce reads it by, each member by the writer its annotation
implies: the bare name when every member it holds is absent, the
object otherwise, a contained entity through its own to_json,
a JSON-valued member copied so the document is not a handle on
the entity. Faithful to every member: read a document, write it
back, and those come out as they went in. The envelope is
written the entity's way -- the bare name when nothing is
configured, the object otherwise, no must_understand, which
means what absence means -- because an entity alone has no
document to be faithful to; ArrayDocumentV3.to_json puts back
the spelling the document used. Ask canonical first if you
want the simplest equivalent spelling.
An entity whose JSON is not its fields overrides this; none in the package does.
Source code in src/zarr_metadata/v3/_entity.py
transition ¶
transition(incoming: ArrayParts) -> ArrayParts | None
The same array with its axes reordered.
A transposed regular grid is still a regular grid, so the parts survive the trip; the grid metadata does not, because it is no longer the grid the document wrote.
Source code in src/zarr_metadata/v3/codec/transpose.py
with_configuration ¶
This entity with these configuration members changed.
codec.with_configuration(typesize=UNSET) is the record rebuilt
through its constructor, which refuses a member of the wrong
type, and the entity rebuilt through its own, which refuses a
value the rules disallow -- the same checks as any construction,
since pyright cannot see the members through **changes. A
name that is not a member is refused the way replace refuses
it.
Source code in src/zarr_metadata/v3/_entity.py
TransposeCodecConfiguration ¶
Bases: TypedDict
Configuration for the Zarr v3 transpose codec.
order is a permutation of the dimension indices 0..n-1 that
specifies the dimension reordering applied during encoding.
Source code in src/zarr_metadata/v3/codec/transpose.py
TransposeCodecObject ¶
Bases: TypedDict
transpose codec metadata in object form.
Source code in src/zarr_metadata/v3/codec/transpose.py
TransposeOptions
dataclass
¶
Bases: Configuration
What transpose is configured with.
Source code in src/zarr_metadata/v3/codec/transpose.py
__post_init__ ¶
Refuse every member of the wrong type, so GzipOptions(level="high") raises.
create_unchecked
classmethod
¶
This record with these members, built without the constructor's check.
The one way around the check, for a caller that has just made
it: the parser, which type-checked every member against the same
annotations before building the record. Every field is given --
the parser gives an absent optional member as UNSET -- since
nothing here applies a default. Anything that has not checked
the members goes through the constructor.
Source code in src/zarr_metadata/v3/_entity.py
problems ¶
problems() -> Iterator[ValidationProblem]
order must permute its own axes.
Whether it permutes the array's axes is a different question -- it needs the array's rank -- and the rules layer asks that one.
Source code in src/zarr_metadata/v3/codec/transpose.py
zarr_metadata.v3.codec.zstd ¶
Zstandard codec types.
See https://github.com/zarr-developers/zarr-extensions/blob/4da7b37a84f76e660902f6d3de3eaef0e0febae6/codecs/zstd/README.md (the zarr-extensions registry entry; zarr-specs PR #256, which first proposed the codec, was never merged).
ZSTD_CODEC_NAME
module-attribute
¶
ZSTD_CODEC_NAME: Final = 'zstd'
The name field value of the zstd codec.
ZSTD_MAX_LEVEL
module-attribute
¶
ZSTD_MAX_LEVEL: Final = 22
The highest level zstd accepts: ZSTD_maxCLevel().
ZSTD_MIN_LEVEL
module-attribute
¶
ZSTD_MIN_LEVEL: Final = -131072
The lowest level zstd accepts: ZSTD_minCLevel(), -(1 << 17).
ZstdCodecMetadata
module-attribute
¶
ZstdCodecMetadata = ZstdCodecObject
Permitted JSON shape for zstd codec metadata.
level is required, so only the object form is valid; the short-hand-name
form is not permitted by the spec for this codec.
https://github.com/zarr-developers/zarr-extensions/blob/4da7b37a84f76e660902f6d3de3eaef0e0febae6/codecs/zstd/README.md#L9-L19
https://github.com/zarr-developers/zarr-specs/blob/fc7dd9c9beb5a50b87f9b08b00bf50fc0048482f/docs/v3/core/index.rst#L1562-L1564 (short-hand names only "if no configuration metadata is required")
ZstdCodecName
module-attribute
¶
ZstdCodecName = Literal['zstd']
Literal type of the name field of the zstd codec.
__all__
module-attribute
¶
__all__ = [
"ZSTD_CODEC_NAME",
"ZSTD_MAX_LEVEL",
"ZSTD_MIN_LEVEL",
"ZstdCodec",
"ZstdCodecConfiguration",
"ZstdCodecMetadata",
"ZstdCodecName",
"ZstdCodecObject",
"ZstdOptions",
]
ZstdCodec
dataclass
¶
Bases: BytesBytesCodec
The zstd codec, coerced from its metadata.
Source code in src/zarr_metadata/v3/codec/zstd.py
configuration
instance-attribute
¶
configuration: ZstdOptions
The record of this entity's members.
An entity with members narrows it to its own record, configuration:
GzipOptions, its one positional argument. An entity of a bare name
defaults it to the empty record -- configuration: Configuration =
field(default_factory=Configuration) -- so that Crc32cCodec()
builds; coerce passes the record either way.
identifier
class-attribute
¶
identifier: str = ZSTD_CODEC_NAME
The name this entity is registered under.
Usually the name the metadata carries. The raw-bytes data types are
the exception: every r<N> spelling is one family, so the family gets
an invented identifier that no real name can collide with.
variable_size
class-attribute
¶
variable_size: bool = True
Whether this codec's output size depends on the bytes it is given.
A compressor's does, so a shard index encoded with one has no size derivable from metadata alone, and the shard cannot be read. Every codec says, because a default in either direction is a verdict.
__post_init__ ¶
Refuse a record that is not this entity's own, then the first problem the rules find.
The runtime half of the entity's type, as the record's constructor
is of the record's: GzipCodec(BloscOptions(...)) and a family
member carrying a name that is not a string are refused before
any rule reads them. Then BloscCodec(BloscOptions(clevel=99))
raises on the first problem the rules yield.
Source code in src/zarr_metadata/v3/_entity.py
accepts
classmethod
¶
Whether name denotes this entity.
Constant for all but the raw-bytes family, where one class covers
every r<N>.
canonical ¶
canonical() -> Self
This entity in the simplest form that means the same thing.
A transformation, asked for by canonicalize_array_metadata_v3
and by nothing else. to_json does not apply it, because writing
a document back is not the same as asking for it to be rewritten:
a reader that reads and writes should not change bytes it was not
asked to change.
The default is the entity itself. Override it where two spellings
of the entity's members mean the same -- a rectilinear
dimension's run-length encoding, a typesize that noshuffle
ignores -- and, in an entity that contains entities, to put those
in canonical form: self.with_configuration(inner=self.inner.canonical()).
Source code in src/zarr_metadata/v3/_entity.py
coerce
classmethod
¶
value as this entity, or the reasons it is not one: the class's validation routine.
resolve relates a field's name to this class and hands it the
field, refined JSON with arrays as tuples, which is what value
is; this is what the class does with it. The configuration is
parsed against the record the configuration field names,
member by member; a member holding another entity is read in
context, the scope this reading is happening in. An optional
member the document left out is UNSET in the record, so no
field's default decides what a document said. The entity is
built only when every member of its own read -- its rules are
written over a whole configuration -- and handed back only when
everything inside it read too.
The envelope is the field's, not the class's, and resolve
judges it: a stray member or a must_understand of false is
not reported here. Called on a class no scope has registered,
this runs with none of registration's refusals having happened.
Source code in src/zarr_metadata/v3/_entity.py
create_unchecked
classmethod
¶
This entity with these fields, built without the constructor's checks.
The one way around them, for a caller that has just made them:
coerce, which type-checked the record and ran the rules before
building. Every field is given -- the record, and the carried
name for a family -- since nothing here applies a default.
Anything that has not checked goes through the constructor.
Source code in src/zarr_metadata/v3/_entity.py
incoming_problems ¶
incoming_problems(
incoming: ArrayParts | None,
) -> tuple[ValidationProblem, ...]
Why this codec cannot be applied to the array that reaches it.
incoming is None once the chain can no longer say what reaches
here, and the default answer to that is nothing: declining beats
guessing. Locations are relative to this codec's configuration;
an empty one lands on the codec itself.
Source code in src/zarr_metadata/v3/_entity.py
inner_pipelines ¶
inner_pipelines(
incoming: ArrayParts | None,
) -> Mapping[
str,
tuple[
Sequence[CodecEntity | Opaque], ArrayParts | None
],
]
The pipelines this codec holds, by the member holding each, with what each is handed.
A shard holds two: its codecs, handed its inner chunk, and its
index_codecs, handed the shard index. Refinement walks them as
it walks the pipeline this codec stands in, locating what it
finds under the member, so a codec that holds pipelines says
which and what they receive, and judges nothing inside them
itself. Default: none.
Source code in src/zarr_metadata/v3/_entity.py
name_problems
classmethod
¶
name_problems(name: str) -> Iterator[ValidationProblem]
Why name, which accepts claimed, is not a well-formed name of this family.
For a family, whose names carry data -- r<N> -- and which claims
a malformed member so that it is reported rather than waved
through as an unknown extension. Locations are relative to the
entity: (). Default: none, for an entity of one name.
Source code in src/zarr_metadata/v3/_entity.py
to_json ¶
to_json() -> ZarrV3MetadataFieldJSON
This entity as a document would write it.
Written from the configuration record by the same declaration
coerce reads it by, each member by the writer its annotation
implies: the bare name when every member it holds is absent, the
object otherwise, a contained entity through its own to_json,
a JSON-valued member copied so the document is not a handle on
the entity. Faithful to every member: read a document, write it
back, and those come out as they went in. The envelope is
written the entity's way -- the bare name when nothing is
configured, the object otherwise, no must_understand, which
means what absence means -- because an entity alone has no
document to be faithful to; ArrayDocumentV3.to_json puts back
the spelling the document used. Ask canonical first if you
want the simplest equivalent spelling.
An entity whose JSON is not its fields overrides this; none in the package does.
Source code in src/zarr_metadata/v3/_entity.py
with_configuration ¶
This entity with these configuration members changed.
codec.with_configuration(typesize=UNSET) is the record rebuilt
through its constructor, which refuses a member of the wrong
type, and the entity rebuilt through its own, which refuses a
value the rules disallow -- the same checks as any construction,
since pyright cannot see the members through **changes. A
name that is not a member is refused the way replace refuses
it.
Source code in src/zarr_metadata/v3/_entity.py
ZstdCodecConfiguration ¶
Bases: TypedDict
Configuration for the Zarr v3 zstd codec.
level is required; checksum is optional ("Should be omitted if
false").
https://github.com/zarr-developers/zarr-extensions/blob/4da7b37a84f76e660902f6d3de3eaef0e0febae6/codecs/zstd/README.md#L9-L19
Source code in src/zarr_metadata/v3/codec/zstd.py
ZstdCodecObject ¶
Bases: TypedDict
zstd codec metadata in object form.
Source code in src/zarr_metadata/v3/codec/zstd.py
ZstdOptions
dataclass
¶
Bases: Configuration
What zstd is configured with.
Source code in src/zarr_metadata/v3/codec/zstd.py
__post_init__ ¶
Refuse every member of the wrong type, so GzipOptions(level="high") raises.
create_unchecked
classmethod
¶
This record with these members, built without the constructor's check.
The one way around the check, for a caller that has just made
it: the parser, which type-checked every member against the same
annotations before building the record. Every field is given --
the parser gives an absent optional member as UNSET -- since
nothing here applies a default. Anything that has not checked
the members goes through the constructor.
Source code in src/zarr_metadata/v3/_entity.py
problems ¶
problems() -> Iterator[ValidationProblem]
Every reason these values are not allowed, yielded as found. Default: none.