zarr_metadata.model
zarr_metadata.model ¶
In-memory models for Zarr metadata documents.
A model holds a metadata document (as written, then refined) and the scope the document was read in. Everything a model returns is read-only.
Every document type has a reader: read_array_metadata_v3,
read_group_metadata_v3, read_consolidated_metadata_v3,
read_array_metadata_v2, read_group_metadata_v2 and
read_consolidated_metadata_v2. A reader checks a document's JSON
structure. In a v3 document it also reads each extension point (codecs,
chunk grids, data types, ...) through the definition that claims its
name in a scope. The scope is CORE_AND_EXTENSIONS unless a context
is passed. A v3 reader checks the fill value against the data type the
document names, the chunk grid against the shape, and the codecs as a
pipeline, each codec against the chunk it receives. Each reader does one
read and returns a reading: what it read, every problem in problems
(a tuple of ValidationProblem, each with a machine-readable kind),
and the model in metadata when there are no problems. A reader is the
form of the model's constructor that returns problems as values instead
of raising them. A node of either type is read by
read_node_metadata_v3, from a zarr.json and its node_type, or by
read_node_metadata_v2, from the node's decoded .zarray or .zgroup
and .zattrs, which can come from a store or from a .zmetadata. To
read a store that another writer made with a known writer bug, use
read_repaired_node_metadata_v3 or read_repaired_node_metadata_v2.
They undo each bug with repair_node_metadata_v3 or
repair_node_metadata_v2 before the strict read, and report what they
changed. zarr_metadata.json_schema writes a JSON Schema of what the v3
readers read, except for the rules. One field on its own is read with
zarr_metadata.definition.resolve.
The model constructors from_json and from_key_value raise
MetadataValidationError for every ingestion failure, including missing
store keys and undecodable bytes. The v3 constructors take the same
context. A v3 model is its document plus the scope it was read in.
ZarrV3ArrayMetadata(document, context=None) reads the document in the
scope and raises MetadataValidationError with every problem, so an
invalid model is never built. to_json returns the document as written.
update reads new members in the model's own scope. with_context and
refined_in read the document in another scope. to_key_value writes
the model as it is. A v3 group reads its consolidated_metadata as an
envelope and does not read the documents it lists, because consolidated
metadata is a convention of the reference implementation, not core
metadata. ZarrV3ConsolidatedMetadata and
read_consolidated_metadata_v3 read those documents. The model also
accepts node models as entries: an entry is accepted when its claims
refine into the model's scope, and refused with a problem at its path
otherwise. Every reader takes context=None for the default scope.
RepairKind
module-attribute
¶
RepairKind: TypeAlias = Literal[
"zero_chunk_length",
"null_consolidated_metadata",
"consolidated_metadata_in_zgroup_entry",
"non_finite_fill_value",
]
The name of each writer bug that a repair undoes.
UNSET
module-attribute
¶
Marks a metadata-document key as absent (PEP 661 sentinel; usable directly
in type expressions, e.g. tuple[str, ...] | UNSET). Test with is UNSET.
ZarrV2NodeMetadata
module-attribute
¶
ZarrV2NodeMetadata = TypeAliasType(
"ZarrV2NodeMetadata",
ZarrV2ArrayMetadata | ZarrV2GroupMetadata,
)
The model of one v2 node, as node_metadata_from_key_value_v2 returns it and a .zmetadata holds it: an array or a group.
ZarrV2NodeMetadataReading
module-attribute
¶
ZarrV2NodeMetadataReading = TypeAliasType(
"ZarrV2NodeMetadataReading",
ZarrV2ArrayMetadataReading
| ZarrV2GroupMetadataReading
| ZarrV2UnknownNodeMetadataReading,
)
A v2 node as read_node_metadata_v2 reads it from a store: as the array or group its files declare, or as neither.
ZarrV3NodeMetadata
module-attribute
¶
ZarrV3NodeMetadata = TypeAliasType(
"ZarrV3NodeMetadata",
ZarrV3ArrayMetadata | ZarrV3GroupMetadata,
)
The model of a v3 zarr.json: an array model or a group model, as its node_type declares.
ZarrV3NodeMetadataInput
module-attribute
¶
ZarrV3NodeMetadataInput = TypeAliasType(
"ZarrV3NodeMetadataInput",
"ZarrV3ArrayMetadataJSON | ZarrV3GroupMetadataJSON | ZarrV3ArrayMetadata | ZarrV3GroupMetadata",
)
An entry of consolidated metadata, at a path, as ZarrV3ConsolidatedMetadata accepts it: a document, or a model of one.
An Input type is what a constructor accepts. A JSON TypedDict is
what a document writes, and an Update type is what update replaces.
Of these three, only an Input may hold a model.
ZarrV3NodeMetadataReading
module-attribute
¶
ZarrV3NodeMetadataReading = TypeAliasType(
"ZarrV3NodeMetadataReading",
ZarrV3ArrayMetadataReading
| ZarrV3GroupMetadataReading
| ZarrV3UnknownNodeMetadataReading,
)
A v3 zarr.json as read_node_metadata_v3 reads it: as the array or group its node_type declares, or as neither.
__all__
module-attribute
¶
__all__ = [
"UNSET",
"Repair",
"RepairKind",
"ZarrV2ArrayMetadata",
"ZarrV2ArrayMetadataReading",
"ZarrV2ArrayMetadataUpdate",
"ZarrV2ConsolidatedMetadata",
"ZarrV2ConsolidatedMetadataReading",
"ZarrV2GroupMetadata",
"ZarrV2GroupMetadataReading",
"ZarrV2GroupMetadataUpdate",
"ZarrV2NodeMetadata",
"ZarrV2NodeMetadataReading",
"ZarrV2RepairedConsolidatedMetadataReading",
"ZarrV2RepairedNodeMetadataReading",
"ZarrV2UnknownNodeMetadataReading",
"ZarrV3ArrayMetadata",
"ZarrV3ArrayMetadataReading",
"ZarrV3ArrayMetadataUpdate",
"ZarrV3ConsolidatedMetadata",
"ZarrV3ConsolidatedMetadataInput",
"ZarrV3ConsolidatedMetadataReading",
"ZarrV3GroupMetadata",
"ZarrV3GroupMetadataReading",
"ZarrV3GroupMetadataUpdate",
"ZarrV3NodeMetadata",
"ZarrV3NodeMetadataInput",
"ZarrV3NodeMetadataReading",
"ZarrV3RepairedNodeMetadataReading",
"ZarrV3UnknownNodeMetadataReading",
"is_node_name_v3",
"is_node_path_v3",
"node_metadata_from_json_v3",
"node_metadata_from_key_value_v2",
"node_metadata_from_key_value_v3",
"parse_node_name_v3",
"parse_node_path_v3",
"read_array_metadata_v2",
"read_array_metadata_v3",
"read_consolidated_metadata_v2",
"read_consolidated_metadata_v3",
"read_group_metadata_v2",
"read_group_metadata_v3",
"read_node_metadata_v2",
"read_node_metadata_v3",
"read_repaired_consolidated_metadata_v2",
"read_repaired_node_metadata_v2",
"read_repaired_node_metadata_v3",
"repair_consolidated_metadata_v2",
"repair_node_metadata_v2",
"repair_node_metadata_v3",
"validate_node_name_v3",
"validate_node_path_v3",
]
Repair
dataclass
¶
One change a repair made to a document: its location, the bug it undid, and what it changed.
Source code in src/zarr_metadata/model/_repair.py
ZarrV2ArrayMetadata ¶
Bases: Keyed
A v2 array document, and the scope it was read in.
Like the v3 models, this model is a pair. to_json returns the merged
document (the .zarray members, plus attributes when a .zattrs
holds them) as written, refined. A .zarray that omits
dimension_separator means "." by the v2 convention
(https://github.com/zarr-developers/zarr-specs/blob/fc7dd9c9beb5a50b87f9b08b00bf50fc0048482f/docs/v2/v2.0.rst#L81-L86):
the dimension_separator property returns ".", and the model compares
equal to one whose document writes ".", but to_json writes the
document without the key. dtype, compressor and
each filter are views of the reading: an AcceptedField read by the
definition in scope that claims the typestr or id, or an
UnclaimedField. attributes is empty when no .zattrs exists, as
in a v3 model. The document still tells the two apart: to_json and
to_key_value write attributes and .zattrs only when a .zattrs
exists, even an empty one. A member the spec does not define is kept
in extra_fields. A model is only built by reading:
the constructor reads document in context and raises
MetadataValidationError with every problem, so no model is invalid.
Two models are equal when their documents mean the same thing in
their scopes, as the model key defines. update reads new members
in the model's own scope. with_context and refined_in read the
document in another scope. A model pickles as its pair.
Source code in src/zarr_metadata/model/_array_v2.py
434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 | |
__slots__
class-attribute
instance-attribute
¶
attributes
property
¶
The user attributes a .zattrs holds, read-only at every level; empty when there is no .zattrs.
compressor
property
¶
compressor: (
AcceptedField[ZarrV2CodecDefinition[Any]]
| UnclaimedField
| None
)
The compressor as the scope read it; None when written as null.
context
property
¶
context: ZarrV2Context
The scope the document was read in. update reads new members in this scope.
dimension_separator
property
¶
dimension_separator: ZarrV2ArrayDimensionSeparator
The separator between chunk indices in a chunk key: "." when the document writes none.
dtype
property
¶
dtype: (
AcceptedField[ZarrV2DataTypeDefinition[Any]]
| UnclaimedField
)
The dtype as the scope read it: read by its family's definition, or unclaimed.
extra_fields
property
¶
Every member the spec does not define, as written, read-only at every level.
fill_value
property
¶
fill_value: JSONValue
The fill value as written, refined; read-only at every level.
filters
property
¶
filters: (
tuple[
AcceptedField[ZarrV2CodecDefinition[Any]]
| UnclaimedField,
...,
]
| None
)
The filters, each as the scope read it; None when written as null.
reading
property
¶
reading: ZarrV2ArrayMetadataReading
The document as the scope read it: the dtype, the compressor, and each filter.
unclaimed_fields
property
¶
unclaimed_fields: dict[Loc, UnclaimedField]
Every field nothing in scope claims, its dtype or a codec, located as reading.fields() locates it: at its place in the document, except that a struct dtype's field types are located by record and position, as their problems are.
This answers whether a reader can open the array: a reader cannot decode data with a dtype or a codec it does not understand, and the scope is what the reader understands. The model only reports these fields; refusing to open is up to the reader.
__eq__ ¶
__init__ ¶
__init__(
document: object, context: ZarrV2Context | None = None
) -> None
Source code in src/zarr_metadata/model/_array_v2.py
__reduce__ ¶
__reduce__() -> tuple[
type[ZarrV2ArrayMetadata], tuple[object, ZarrV2Context]
]
create_default
classmethod
¶
create_default(
*,
context: ZarrV2Context | None = None,
**overrides: Unpack[ZarrV2ArrayMetadataUpdate],
) -> ZarrV2ArrayMetadata
Return a scalar |u1 array, with any document members in overrides applied, read in context.
Raises MetadataValidationError when the resulting document has a
problem. Overriding shape without chunks sets chunks equal to
shape, so one chunk covers the array. Overriding chunks without
shape keeps the scalar default shape, which chunks of another
rank do not fit. A dtype given without a fill value gets a fill
value of 0 when its family accepts 0, and null otherwise.
Every family accepts null.
Source code in src/zarr_metadata/model/_array_v2.py
from_json
classmethod
¶
from_json(
data: object, *, context: ZarrV2Context | None = None
) -> ZarrV2ArrayMetadata
Return the model of data, a v2 array document with its attributes under attributes, read in context.
Raises MetadataValidationError with every problem the read finds.
read_array_metadata_v2 returns the reading this model is built
from, and the problems of a document that has any.
Source code in src/zarr_metadata/model/_array_v2.py
from_key_value
classmethod
¶
from_key_value(
mapping: Mapping[StoreKey, bytes],
*,
context: ZarrV2Context | None = None,
) -> ZarrV2ArrayMetadata
Return the model of the array at .zarray in mapping, with the attributes at .zattrs when that key exists, read in context.
Raises MetadataValidationError when .zarray is missing, bytes
are not JSON, .zarray holds attributes, or the document is not
valid, with every problem the read finds. Raises TypeError for a
scope of another format before any bytes are decoded.
Source code in src/zarr_metadata/model/_array_v2.py
refined_in ¶
refined_in(
context: ZarrV2Context | None = None,
) -> ZarrV2ArrayMetadata
Return this document read in context. context may claim names this scope left unclaimed, but must not contradict any claim.
Raises ScopeConflictError when context reads a typestr or id
with a different definition, or with no definition, where this
scope read it with one. The error names each one and its location
in the document. Raises MetadataValidationError when a definition
that context claims rejects what was written.
Source code in src/zarr_metadata/model/_array_v2.py
refines ¶
refines(other: ZarrV2ArrayMetadata) -> bool
Whether this model holds everything other holds. Each field must refine its counterpart. A null compressor or null filters refine only a null. Every other member must be the same, with the fill value compared in the spelling of the more informed dtype. If that dtype rejects the other model's fill value, this is not a refinement.
Source code in src/zarr_metadata/model/_array_v2.py
to_json ¶
to_json() -> ZarrV2ArrayMetadataJSON
The merged document as written, refined. The result shares no objects with the model.
attributes is included when set, even empty. This is not the
on-disk .zarray, which excludes them: to_key_value splits the
document as a store holds it
(https://github.com/zarr-developers/zarr-specs/blob/fc7dd9c9beb5a50b87f9b08b00bf50fc0048482f/docs/v2/v2.0.rst#L323-L330).
Source code in src/zarr_metadata/model/_array_v2.py
to_key_value ¶
to_key_value(
*, indent: int | str | None = None
) -> Mapping[
ZarrV2ArrayMetadataStoreKey | ZarrV2AttributesStoreKey,
bytes,
]
The document as a store holds it: .zarray without the attributes, and .zattrs with the attributes when they are set, even if empty.
Source code in src/zarr_metadata/model/_array_v2.py
update ¶
update(
**members: Unpack[ZarrV2ArrayMetadataUpdate],
) -> ZarrV2ArrayMetadata
Return this model with members (as JSON) replacing the document's members, read in this model's own scope. A member set to UNSET is removed.
Raises MetadataValidationError when the resulting document has a
problem. So members that depend on each other must be passed
together, for example a dtype with a fill value of that dtype.
Source code in src/zarr_metadata/model/_array_v2.py
with_context ¶
with_context(
context: ZarrV2Context | None = None,
) -> ZarrV2ArrayMetadata
Return this document read in context, whatever that changes: a gain, a loss, or a conflict.
Raises MetadataValidationError when the document has a problem
in context. The existing reading is reused when context reads
every claim identically.
Source code in src/zarr_metadata/model/_array_v2.py
ZarrV2ArrayMetadataReading
dataclass
¶
A v2 array document as a scope read it, whatever it holds: its dtype, compressor and filters, every problem, and the model when there are no problems.
A field the document does not hold is UNSET, and so is a filters
that is not an array, which holds no filters to read. A compressor
or filters written as null is None.
Source code in src/zarr_metadata/model/_array_v2.py
compressor
class-attribute
instance-attribute
¶
compressor: (
ResolvedField[ZarrV2CodecDefinition[Any]] | UNSET | None
) = UNSET
The compressor, as the scope read it; None when written as null.
dtype
class-attribute
instance-attribute
¶
dtype: (
ResolvedField[ZarrV2DataTypeDefinition[Any]] | UNSET
) = UNSET
The dtype, as the scope read it.
filters
class-attribute
instance-attribute
¶
filters: (
tuple[ResolvedField[ZarrV2CodecDefinition[Any]], ...]
| UNSET
| None
) = UNSET
The filters, each as the scope read it; None when written as null.
metadata
class-attribute
instance-attribute
¶
metadata: ZarrV2ArrayMetadata | None = None
The document's model, which holds these fields, when there is no problem; None otherwise.
problems
class-attribute
instance-attribute
¶
problems: tuple[ValidationProblem, ...] = ()
Every reason the document is not valid.
__init__ ¶
__init__(
dtype: ResolvedField[ZarrV2DataTypeDefinition[Any]]
| UNSET = UNSET,
compressor: ResolvedField[ZarrV2CodecDefinition[Any]]
| UNSET
| None = UNSET,
filters: tuple[
ResolvedField[ZarrV2CodecDefinition[Any]], ...
]
| UNSET
| None = UNSET,
problems: tuple[ValidationProblem, ...] = (),
metadata: ZarrV2ArrayMetadata | None = None,
) -> None
__reduce__ ¶
fields ¶
fields() -> Iterator[tuple[Loc, ResolvedField[Any]]]
Each field in the document, as the scope read it, with its location: the dtype, followed by a struct's record types, then the compressor, then each filter at its index.
Source code in src/zarr_metadata/model/_array_v2.py
ZarrV2ArrayMetadataUpdate ¶
Bases: TypedDict
The members ZarrV2ArrayMetadata.update replaces: each in the form a document writes it, or UNSET to remove a member that a document may omit.
The members a document may omit are attributes (meaning no
.zattrs), dimension_separator (read as "."), and any member the
spec does not define. Those go in extra_fields, by key: each one
given is set, or removed when given as UNSET, and the others are
kept. A member is given by its own name only when the spec defines it,
so a misspelled name is refused.
Source code in src/zarr_metadata/model/_array_v2.py
ZarrV2ConsolidatedMetadata ¶
Bases: Keyed
A v2 .zmetadata document, and the scope its nodes were read in.
metadata maps the path of each node to its model in this scope, as
ZarrV3ConsolidatedMetadata.metadata does. A path is written without
the leading /, and the root's path is "": the node at /a/b is at
a/b. Each node is a .zarray or .zgroup entry, merged with its
sibling .zattrs. A .zattrs with no sibling is kept but does not
form a node. Any other entry must be JSON, and is kept. to_json
returns the entries keyed by file ("a/.zarray", "a/.zattrs", ...)
as written, refined, so the document still tells which nodes have a
.zattrs at all. A model is only built by reading: the constructor
raises MetadataValidationError with every problem, each located
under its entry. Two documents are equal when each node means the same
thing and the other entries are written the same way, as the model
key defines. refines, with_context and refined_in work through
the nodes.
Source code in src/zarr_metadata/model/_group_v2.py
464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 | |
__slots__
class-attribute
instance-attribute
¶
metadata
property
¶
metadata: Mapping[str, ZarrV2NodeMetadata]
A read-only view of the model of each node, keyed by its path without the leading / ("" for the root).
reading
property
¶
reading: ZarrV2ConsolidatedMetadataReading
The document as the scope read it: no problems, and this model.
__eq__ ¶
__init__ ¶
__init__(
document: object, context: ZarrV2Context | None = None
) -> None
Source code in src/zarr_metadata/model/_group_v2.py
__reduce__ ¶
__reduce__() -> tuple[
type[ZarrV2ConsolidatedMetadata],
tuple[object, ZarrV2Context],
]
from_json
classmethod
¶
from_json(
data: object, *, context: ZarrV2Context | None = None
) -> ZarrV2ConsolidatedMetadata
Return the model of data, a .zmetadata document, with its nodes read in context. Raises MetadataValidationError with every problem.
Source code in src/zarr_metadata/model/_group_v2.py
from_key_value
classmethod
¶
from_key_value(
mapping: Mapping[StoreKey, bytes],
*,
context: ZarrV2Context | None = None,
) -> ZarrV2ConsolidatedMetadata
Return the model of the document at .zmetadata in mapping, read in context.
Raises MetadataValidationError when the key is missing, its bytes
are not JSON, or the document is not valid. Raises TypeError for
a scope of another format before the bytes are decoded.
Source code in src/zarr_metadata/model/_group_v2.py
refined_in ¶
refined_in(
context: ZarrV2Context | None = None,
) -> ZarrV2ConsolidatedMetadata
Return this document with every node read in context. context may claim names this scope left unclaimed, but must not contradict any claim.
Raises ScopeConflictError naming each conflict, located at the
node's entry. Raises MetadataValidationError when a gain exposes
a problem.
Source code in src/zarr_metadata/model/_group_v2.py
refines ¶
refines(other: ZarrV2ConsolidatedMetadata) -> bool
Whether every node this holds refines the node other holds at the same path, both hold the same paths, and the other entries are written the same way. False when other is not v2 consolidated metadata.
Source code in src/zarr_metadata/model/_group_v2.py
to_json ¶
The .zmetadata document as written, refined. The result shares no objects with the model.
to_key_value ¶
to_key_value(
*, indent: int | str | None = None
) -> Mapping[ZarrV2ConsolidatedMetadataStoreKey, bytes]
The document as a store holds it: JSON bytes at .zmetadata, indented by indent.
Source code in src/zarr_metadata/model/_group_v2.py
with_context ¶
with_context(
context: ZarrV2Context | None = None,
) -> ZarrV2ConsolidatedMetadata
Return this document with every node read in context, whatever that changes. Raises MetadataValidationError when a node has a problem in context.
Source code in src/zarr_metadata/model/_group_v2.py
ZarrV2ConsolidatedMetadataReading
dataclass
¶
A v2 .zmetadata document as a scope read it: every problem, and the model when there are no problems.
Source code in src/zarr_metadata/model/_group_v2.py
metadata
class-attribute
instance-attribute
¶
metadata: ZarrV2ConsolidatedMetadata | None = None
The document's model when there is no problem; None otherwise.
problems
class-attribute
instance-attribute
¶
problems: tuple[ValidationProblem, ...] = ()
Every reason the document is not valid.
__init__ ¶
__init__(
problems: tuple[ValidationProblem, ...] = (),
metadata: ZarrV2ConsolidatedMetadata | None = None,
) -> None
__reduce__ ¶
fields ¶
fields() -> Iterator[tuple[Loc, ResolvedField[Any]]]
Each field of each array node, as read, located in the .zmetadata: under the node's .zarray entry, at the key the document writes for it. Nothing when there is no model, and nothing for a group, which has no fields.
Source code in src/zarr_metadata/model/_group_v2.py
ZarrV2GroupMetadata ¶
Bases: Keyed
A v2 group document, and the scope it was read in.
Like the v3 models, this model is a pair. to_json returns the
merged document (.zgroup, plus attributes when a .zattrs holds
them) as written, refined. attributes is empty when no .zattrs
exists, as in a v3 model. The document still tells the two apart:
to_json and to_key_value write attributes and .zattrs only when
a .zattrs exists, even an empty one. A group has no fields
for a scope to read, so the scope is held only for consistency with
the other models: update reads new attributes in it, and no other
scope conflicts with the reading. A model is only built by reading:
the constructor raises MetadataValidationError with every problem.
Two groups are equal when their attributes are written the same way,
as _key_of defines; no .zattrs and an empty one are equal.
Source code in src/zarr_metadata/model/_group_v2.py
243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 | |
__slots__
class-attribute
instance-attribute
¶
attributes
property
¶
The user attributes a .zattrs holds, read-only at every level; empty when there is no .zattrs.
context
property
¶
context: ZarrV2Context
The scope the document was read in. update reads new attributes in this scope.
reading
property
¶
reading: ZarrV2GroupMetadataReading
The document as the scope read it: no problems, and this model.
unclaimed_fields
property
¶
unclaimed_fields: dict[Loc, UnclaimedField]
Every field nothing in scope claims. A v2 group holds no fields, so this is always empty; it is here so a reader can ask any node the same question.
__eq__ ¶
__init__ ¶
__init__(
document: object, context: ZarrV2Context | None = None
) -> None
Source code in src/zarr_metadata/model/_group_v2.py
__reduce__ ¶
__reduce__() -> tuple[
type[ZarrV2GroupMetadata], tuple[object, ZarrV2Context]
]
create_default
classmethod
¶
create_default(
*,
context: ZarrV2Context | None = None,
**overrides: Unpack[ZarrV2GroupMetadataUpdate],
) -> ZarrV2GroupMetadata
Return a group with no .zattrs, with overrides applied, read in context. Raises MetadataValidationError when the resulting document has a problem.
Source code in src/zarr_metadata/model/_group_v2.py
from_json
classmethod
¶
from_json(
data: object, *, context: ZarrV2Context | None = None
) -> ZarrV2GroupMetadata
Return the model of data, a v2 group document with its attributes under attributes, read in context. Raises MetadataValidationError with every problem.
Source code in src/zarr_metadata/model/_group_v2.py
from_key_value
classmethod
¶
from_key_value(
mapping: Mapping[StoreKey, bytes],
*,
context: ZarrV2Context | None = None,
) -> ZarrV2GroupMetadata
Return the model of the group at .zgroup in mapping, with the attributes at .zattrs when that key exists, read in context.
Raises MetadataValidationError when .zgroup is missing, bytes
are not JSON, .zgroup holds attributes, or the document is not
valid, with every problem the read finds. Raises TypeError for a
scope of another format before any bytes are decoded.
Source code in src/zarr_metadata/model/_group_v2.py
refined_in ¶
refined_in(
context: ZarrV2Context | None = None,
) -> ZarrV2GroupMetadata
Return this document read in context. A group has no fields, so no scope conflicts with its reading, and this is the same as with_context.
Source code in src/zarr_metadata/model/_group_v2.py
refines ¶
refines(other: ZarrV2GroupMetadata) -> bool
Whether this group holds everything other holds, which means its attributes are written the same way, no .zattrs counting as empty attributes. False when other is not a v2 group.
Source code in src/zarr_metadata/model/_group_v2.py
to_json ¶
to_json() -> ZarrV2GroupMetadataJSON
The merged document as written, refined. The result shares no objects with the model.
attributes is included when set, even if empty. This is not the
on-disk .zgroup, which excludes them: to_key_value splits the
document as a store holds it
(https://github.com/zarr-developers/zarr-specs/blob/fc7dd9c9beb5a50b87f9b08b00bf50fc0048482f/docs/v2/v2.0.rst#L313; https://github.com/zarr-developers/zarr-specs/blob/fc7dd9c9beb5a50b87f9b08b00bf50fc0048482f/docs/v2/v2.0.rst#L323-L330).
Source code in src/zarr_metadata/model/_group_v2.py
to_key_value ¶
to_key_value(
*, indent: int | str | None = None
) -> Mapping[
ZarrV2GroupMetadataStoreKey | ZarrV2AttributesStoreKey,
bytes,
]
The document as a store holds it: .zgroup without the attributes, and .zattrs with the attributes when they are set, even if empty.
Source code in src/zarr_metadata/model/_group_v2.py
update ¶
update(
**members: Unpack[ZarrV2GroupMetadataUpdate],
) -> ZarrV2GroupMetadata
Return this model with attributes replacing the document's attributes, read in this model's own scope. UNSET removes them. Raises MetadataValidationError when the resulting document has a problem.
Source code in src/zarr_metadata/model/_group_v2.py
with_context ¶
with_context(
context: ZarrV2Context | None = None,
) -> ZarrV2GroupMetadata
Return this document read in context: the same group, holding that scope.
Source code in src/zarr_metadata/model/_group_v2.py
ZarrV2GroupMetadataReading
dataclass
¶
A v2 group document as a scope read it: every problem, and the model when there are no problems. A group has no fields for a scope to read.
Source code in src/zarr_metadata/model/_group_v2.py
metadata
class-attribute
instance-attribute
¶
metadata: ZarrV2GroupMetadata | None = None
The document's model when there is no problem; None otherwise.
problems
class-attribute
instance-attribute
¶
problems: tuple[ValidationProblem, ...] = ()
Every reason the document is not valid.
__init__ ¶
__init__(
problems: tuple[ValidationProblem, ...] = (),
metadata: ZarrV2GroupMetadata | None = None,
) -> None
__reduce__ ¶
ZarrV2GroupMetadataUpdate ¶
Bases: TypedDict
The members ZarrV2GroupMetadata.update replaces: attributes in the form a .zattrs writes them, or UNSET for no .zattrs.
Source code in src/zarr_metadata/model/_group_v2.py
ZarrV2RepairedConsolidatedMetadataReading
dataclass
¶
A v2 .zmetadata read after its known writer bugs were undone: the strict reading of the repaired document, and the repairs.
Source code in src/zarr_metadata/model/_repair.py
reading
instance-attribute
¶
reading: ZarrV2ConsolidatedMetadataReading
The repaired document, as read_consolidated_metadata_v2 reads it. The problems are those of the repaired document. The model is present when there are no problems.
repairs
instance-attribute
¶
The changes that produced the document that was read.
__init__ ¶
__init__(
reading: ZarrV2ConsolidatedMetadataReading,
repairs: tuple[Repair, ...],
) -> None
ZarrV2RepairedNodeMetadataReading
dataclass
¶
A v2 node's files read after their known writer bugs were undone: the strict reading of the repaired files, and the repairs.
Source code in src/zarr_metadata/model/_repair.py
reading
instance-attribute
¶
reading: ZarrV2NodeMetadataReading
The repaired files, as read_node_metadata_v2 reads them. The problems are those of the repaired files. The model is present when there are no problems.
repairs
instance-attribute
¶
The changes that produced the files that were read.
ZarrV2UnknownNodeMetadataReading
dataclass
¶
A store that holds no v2 node: neither a .zarray nor a .zgroup, or both. The problems say which.
Source code in src/zarr_metadata/model/_group_v2.py
ZarrV3ArrayMetadata ¶
Bases: Keyed
A v3 array document, and the scope it was read in.
The model is this pair. to_json returns the document as written,
refined (arrays as tuples, string keys), and context is the scope.
Every typed member is a view of the reading of the document in the
scope. data_type, chunk_grid, chunk_key_encoding, and each codec
and storage transformer are fields as the scope read them: an
AcceptedField (read by the definition that claims its name) or an
UnclaimedField, and so is each member in extra_fields, which the
spec does not define. shape, fill_value, dimension_names and
attributes are the values the read refined. A
model is only built by reading: the constructor reads document in
context and raises MetadataValidationError with every problem, so
no model is invalid. Two models are equal when their documents mean
the same thing in their scopes, as the model key defines. The scope
itself is not compared. update reads new members in the model's own
scope. with_context and refined_in read the document in another
scope. A model pickles as its pair, provided the definitions in its
scope can be pickled, which requires their functions to be defined at
the top level of a module.
Source code in src/zarr_metadata/model/_array_v3.py
473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 | |
__slots__
class-attribute
instance-attribute
¶
attributes
property
¶
The attributes, read-only at every level; empty when the document writes none.
chunk_grid
property
¶
chunk_grid: (
AcceptedField[ChunkGridDefinition[Any]] | UnclaimedField
)
The chunk grid, as the scope read it.
chunk_key_encoding
property
¶
chunk_key_encoding: (
AcceptedField[ChunkKeyEncodingDefinition[Any]]
| UnclaimedField
)
The chunk key encoding, as the scope read it.
codecs
property
¶
codecs: tuple[
AcceptedField[CodecDefinition[Any]] | UnclaimedField,
...,
]
The codecs, each as the scope read it, in pipeline order.
context
property
¶
context: ZarrV3Context
The scope the document was read in. update reads new members in this scope.
data_type
property
¶
data_type: (
AcceptedField[DataTypeDefinition[Any]] | UnclaimedField
)
The data type, as the scope read it.
dimension_names
property
¶
The dimension names; UNSET when the document writes none.
extra_fields
property
¶
extra_fields: Mapping[
str,
AcceptedField[ArrayExtraFieldDefinition[Any]]
| UnclaimedField,
]
Each member the spec does not define, by key, as the scope read it: an AcceptedField when a definition in scope claims the key, and an UnclaimedField otherwise.
must_understand_fields
property
¶
must_understand_fields: dict[str, ZarrV3ExtensionField]
The extra fields, by key and as written, that no definition in scope reads and that a reader is obligated to understand.
Each unclaimed member of extra_fields not explicitly waived with
must_understand: false (the spec's implicit-true rule, https://github.com/zarr-developers/zarr-specs/blob/fc7dd9c9beb5a50b87f9b08b00bf50fc0048482f/docs/v3/core/index.rst#L1571-L1578). The scope is what
the reader recognizes, so a compliant reader MUST fail to open the
array when this is not empty. The model only reports these fields;
refusing to open is up to the reader.
reading
property
¶
reading: ZarrV3ArrayMetadataReading
The document as the scope read it: each field, the pipeline, and the chunk each codec receives.
storage_transformers
property
¶
storage_transformers: tuple[
AcceptedField[StorageTransformerDefinition[Any]]
| UnclaimedField,
...,
]
The storage transformers, each as the scope read it.
unclaimed_fields
property
¶
unclaimed_fields: dict[Loc, UnclaimedField]
Every field nothing in scope claims, at any depth, by its location in the document, except an extra member that says "must_understand": false and every field inside it, claimed or not, since a reader may ignore such a member whole.
This answers whether a reader can open the array: the spec requires a reader to refuse a node with a field it does not understand, and the scope is what the reader understands. A codec inside a shard is located inside the shard's configuration. The model only reports these fields; refusing to open is up to the reader.
__eq__ ¶
__init__ ¶
__init__(
document: object, context: ZarrV3Context | None = None
) -> None
Source code in src/zarr_metadata/model/_array_v3.py
__reduce__ ¶
__reduce__() -> tuple[
type[ZarrV3ArrayMetadata], tuple[object, ZarrV3Context]
]
Source code in src/zarr_metadata/model/_array_v3.py
create_default
classmethod
¶
create_default(
*,
context: ZarrV3Context | None = None,
**overrides: Unpack[ZarrV3ArrayMetadataUpdate],
) -> ZarrV3ArrayMetadata
Return a scalar uint8 array, with any document members in overrides applied, read in context. overrides takes what update takes, including UNSET to drop a member.
Raises MetadataValidationError when the resulting document has a
problem. So members that depend on each other must be passed
together: a data type with a fill value of that type, or a grid
with the shape it fits. The default codec is bytes with little
endian, which accepts a data type of any fixed size. Overriding
shape without chunk_grid derives a consistent default grid: one
regular chunk covering the array (chunk_shape equal to shape,
with a length of 1 for a dimension of length 0, since "Chunk sizes
must be greater than zero",
https://github.com/zarr-developers/zarr-specs/blob/fc7dd9c9beb5a50b87f9b08b00bf50fc0048482f/docs/v3/chunk-grids/regular-grid/index.rst#L40).
Source code in src/zarr_metadata/model/_array_v3.py
from_json
classmethod
¶
from_json(
data: object, *, context: ZarrV3Context | None = None
) -> ZarrV3ArrayMetadata
Return the model of data, a v3 array document read in context.
Raises MetadataValidationError with every problem the read finds.
read_array_metadata_v3 returns the reading this model is built
from, and the problems of a document that has any.
Source code in src/zarr_metadata/model/_array_v3.py
from_key_value
classmethod
¶
from_key_value(
mapping: Mapping[StoreKey, bytes],
*,
context: ZarrV3Context | None = None,
) -> ZarrV3ArrayMetadata
Return the model of the array document at zarr.json in mapping, read in context.
Raises MetadataValidationError when the key is missing, its bytes
are not JSON, or the document is not valid. Raises TypeError for
a scope of another format before any bytes are decoded.
Source code in src/zarr_metadata/model/_array_v3.py
refined_in ¶
refined_in(
context: ZarrV3Context | None = None,
) -> ZarrV3ArrayMetadata
Return this document read in context. context may claim names this scope left unclaimed, but must not contradict any claim.
Raises ScopeConflictError when context reads a name with a
different definition, or with no definition, where this scope read
it with one. A loss of meaning is refused in the same way as a
conflict. The error names each such name and its location in the
document. Raises MetadataValidationError when a definition that
context newly claims rejects what was written under its name: a
gain can expose a problem. with_context reads the document in
any scope.
Source code in src/zarr_metadata/model/_array_v3.py
refines ¶
refines(other: ZarrV3ArrayMetadata) -> bool
Whether this model holds everything other holds. Each field must refine its counterpart, in the order refines defines for fields (including the fields nested in each field). Every other member must be the same, with the fill value compared in the spelling of the more informed data type. If that data type rejects the other model's fill value, this is not a refinement.
Source code in src/zarr_metadata/model/_array_v3.py
to_json ¶
to_json() -> ZarrV3ArrayMetadataJSON
The document as written, refined. The result shares no objects with the model.
to_key_value ¶
to_key_value(
*, indent: int | str | None = None
) -> Mapping[ZarrV3ArrayMetadataStoreKey, bytes]
The document as a store holds it: JSON bytes at zarr.json, indented by indent.
NaN, Infinity and -Infinity in attributes are written as
bare tokens, as zarr-python writes them. A strict JSON parser
rejects these tokens.
Source code in src/zarr_metadata/model/_array_v3.py
update ¶
update(
**members: Unpack[ZarrV3ArrayMetadataUpdate],
) -> ZarrV3ArrayMetadata
Return this model with members (as JSON) replacing the document's members, read in this model's own scope. A member set to UNSET is removed. A member the spec does not define is given in extra_fields.
Raises TypeError for a member the update does not take. Raises
MetadataValidationError when the resulting document has a
problem. So members that depend on each other must be passed
together, for example a shape with a grid that fits it.
Source code in src/zarr_metadata/model/_array_v3.py
with_context ¶
with_context(
context: ZarrV3Context | None = None,
) -> ZarrV3ArrayMetadata
Return this document read in context, whatever that changes: a gain, a loss, or a conflict.
Raises MetadataValidationError when the document has a problem
in context. The existing reading is reused when context reads
every claim identically.
Source code in src/zarr_metadata/model/_array_v3.py
ZarrV3ArrayMetadataReading
dataclass
¶
A v3 array document as a scope read it, whatever it holds: each extension point, its codecs as a pipeline, every problem, and the model when there are no problems.
A field the document does not have is UNSET. A list of fields that
the document does not have as a list is empty.
Source code in src/zarr_metadata/model/_array_v3.py
chunk
class-attribute
instance-attribute
¶
chunk: Chunk = dataclasses.field(default_factory=Chunk)
The chunks the first codec receives: the length of the grid's chunks along each axis of the shape, and the data type.
chunk_grid
class-attribute
instance-attribute
¶
chunk_grid: (
ResolvedField[ChunkGridDefinition[Any]] | UNSET
) = UNSET
The chunk grid, as the scope read it.
chunk_key_encoding
class-attribute
instance-attribute
¶
chunk_key_encoding: (
ResolvedField[ChunkKeyEncodingDefinition[Any]] | UNSET
) = UNSET
The chunk key encoding, as the scope read it.
data_type
class-attribute
instance-attribute
¶
data_type: (
ResolvedField[DataTypeDefinition[Any]] | UNSET
) = UNSET
The data type, as the scope read it.
extra_fields
class-attribute
instance-attribute
¶
extra_fields: Mapping[
str, ResolvedField[ArrayExtraFieldDefinition[Any]]
] = dataclasses.field(default_factory=no_extra_fields)
Each member the spec does not define, as the scope read it, by key: an UnclaimedField when no definition in scope claims the key.
metadata
class-attribute
instance-attribute
¶
metadata: ZarrV3ArrayMetadata | None = None
The document's model, which holds these fields, when there is no problem; None otherwise.
pipeline
class-attribute
instance-attribute
¶
The codecs, read as a pipeline: each as the scope read it, with the chunk it receives.
problems
class-attribute
instance-attribute
¶
problems: tuple[ValidationProblem, ...] = ()
Every reason the document is not valid.
storage_transformers
class-attribute
instance-attribute
¶
storage_transformers: tuple[
ResolvedField[StorageTransformerDefinition[Any]], ...
] = ()
The storage transformers, each as the scope read it.
__init__ ¶
__init__(
data_type: ResolvedField[DataTypeDefinition[Any]]
| UNSET = UNSET,
chunk_grid: ResolvedField[ChunkGridDefinition[Any]]
| UNSET = UNSET,
chunk_key_encoding: ResolvedField[
ChunkKeyEncodingDefinition[Any]
]
| UNSET = UNSET,
chunk: Chunk = Chunk(),
pipeline: tuple[Stage, ...] = (),
storage_transformers: tuple[
ResolvedField[StorageTransformerDefinition[Any]],
...,
] = (),
extra_fields: Mapping[
str, ResolvedField[ArrayExtraFieldDefinition[Any]]
] = no_extra_fields(),
problems: tuple[ValidationProblem, ...] = (),
metadata: ZarrV3ArrayMetadata | None = None,
) -> None
__reduce__ ¶
Source code in src/zarr_metadata/model/_array_v3.py
fields ¶
fields() -> Iterator[tuple[Loc, ResolvedField[Any]]]
Each field in the document, as the scope read it, with its location in the document.
The order is: the extension points, then each codec and storage
transformer at its index, then each extra field at its key. Each is
followed by the fields nested in it, as fields_of returns them: a
shard's codecs, or a struct's field types. with_problems returns
each field with its problems.
Source code in src/zarr_metadata/model/_array_v3.py
ZarrV3ArrayMetadataUpdate ¶
Bases: TypedDict
The members ZarrV3ArrayMetadata.update replaces: each in the form a document writes it, or UNSET to remove a member that a document may omit.
The members a document may omit are dimension_names, attributes,
storage_transformers, and any member the spec does not define. Those
go in extra_fields, by key: each one given is set, or removed when
given as UNSET, and the others are kept. A member is given by its own
name only when the spec defines it, so a misspelled name is refused.
Source code in src/zarr_metadata/model/_array_v3.py
storage_transformers
instance-attribute
¶
storage_transformers: (
tuple[ZarrV3MetadataFieldJSON, ...] | UNSET
)
ZarrV3ConsolidatedMetadata ¶
Bases: Keyed
A group's inline consolidated_metadata member with every document it lists read, and the scope they were read in.
Models the reference-implementation convention where consolidated
metadata is embedded in a group's zarr.json. A group's own read
checks only the member's envelope. This model reads each document the
member lists, once, as the array or group its node_type declares,
and checks that the documents and the group form a hierarchy with the
group as its root. Build it to check consolidated metadata before
ZarrV3GroupMetadata.update writes it into a group. metadata maps
each path to the model, in this scope, of the document at that path.
Each document is stored at its node's path without the leading /:
the node at /a/b is at a/b. kind is inline and
must_understand is False, as the convention declares. A model is
only built by reading: the constructor raises
MetadataValidationError with every problem, located in the member.
Source code in src/zarr_metadata/model/_group_v3.py
473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 | |
metadata
property
¶
metadata: Mapping[str, ZarrV3NodeMetadata]
A read-only view of the model of each document, keyed by its path below the group.
reading
property
¶
reading: ZarrV3ConsolidatedMetadataReading
The member as the scope read it: no problems, and this model.
__eq__ ¶
__init__ ¶
__init__(
member: object, context: ZarrV3Context | None = None
) -> None
Source code in src/zarr_metadata/model/_group_v3.py
__reduce__ ¶
__reduce__() -> tuple[
type[ZarrV3ConsolidatedMetadata],
tuple[object, ZarrV3Context],
]
from_json
classmethod
¶
from_json(
data: object, *, context: ZarrV3Context | None = None
) -> ZarrV3ConsolidatedMetadata
Return the model of data, a group's consolidated_metadata member. Each document is read once in context, as the array or group its node_type declares. Raises MetadataValidationError with every problem found.
Source code in src/zarr_metadata/model/_group_v3.py
refined_in ¶
refined_in(
context: ZarrV3Context | None = None,
) -> ZarrV3ConsolidatedMetadata
Return this member with every document read in context. context may claim names this scope left unclaimed, but must not contradict any claim.
Raises ScopeConflictError naming each conflict, located at the
document's path. Raises MetadataValidationError when a gain
exposes a problem.
Source code in src/zarr_metadata/model/_group_v3.py
refines ¶
refines(other: ZarrV3ConsolidatedMetadata) -> bool
Whether every document this holds refines the document other holds at the same path, and both hold the same paths. False when other is not consolidated metadata.
Source code in src/zarr_metadata/model/_group_v3.py
to_json ¶
to_json() -> ZarrV3ConsolidatedMetadataJSON
The member as written, refined. The result shares no objects with the model.
with_context ¶
with_context(
context: ZarrV3Context | None = None,
) -> ZarrV3ConsolidatedMetadata
Return this member with every document read in context, whatever that changes. Raises MetadataValidationError when a document has a problem in context. The existing readings are reused when context reads every claim of every document identically.
Source code in src/zarr_metadata/model/_group_v3.py
ZarrV3ConsolidatedMetadataInput ¶
Bases: TypedDict
The consolidated_metadata member as ZarrV3ConsolidatedMetadata accepts it: in the form a document writes it, with each entry a document or a node model.
A node model is accepted when the scope of the consolidated metadata reads every one of its claims identically, or claims names the model's scope left unclaimed. In the second case the model's document is read again in that scope. A node model is refused, with a problem at its path, when the two scopes read a name differently, or when the scope of the consolidated metadata leaves a claimed name unclaimed.
Source code in src/zarr_metadata/model/_group_v3.py
ZarrV3ConsolidatedMetadataReading
dataclass
¶
A group's consolidated_metadata member as a scope read it: every problem, and the model when there are no problems.
Source code in src/zarr_metadata/model/_group_v3.py
metadata
class-attribute
instance-attribute
¶
metadata: ZarrV3ConsolidatedMetadata | None = None
The member's model when there is no problem; None otherwise.
problems
class-attribute
instance-attribute
¶
problems: tuple[ValidationProblem, ...] = ()
Every reason the member is not valid.
__init__ ¶
__init__(
problems: tuple[ValidationProblem, ...] = (),
metadata: ZarrV3ConsolidatedMetadata | None = None,
) -> None
__reduce__ ¶
fields ¶
fields() -> Iterator[tuple[Loc, ResolvedField[Any]]]
Each field of each document, as read, located in the member: under metadata and the document's path. Nothing when there is no model.
Source code in src/zarr_metadata/model/_group_v3.py
ZarrV3GroupMetadata ¶
Bases: Keyed
A v3 group document, and the scope it was read in.
Like ZarrV3ArrayMetadata, the model is this pair. to_json returns
the document as written, refined, and context is the scope.
attributes and consolidated_metadata are views of the values the
read refined. Each member the spec does not define is an extra field,
in extra_fields, as the scope read it. CORE reads a
consolidated_metadata member as the envelope the core spec fixes,
and no definition reads the documents the member lists: they follow a
convention of the reference implementation, not the core spec. To
read them, pass the member to ZarrV3ConsolidatedMetadata or
read_consolidated_metadata_v3, or read one listed document with
read_node_metadata_v3. A model is only built by reading: the
constructor reads document in context and raises
MetadataValidationError with every problem.
Source code in src/zarr_metadata/model/_group_v3.py
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 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 | |
__slots__
class-attribute
instance-attribute
¶
attributes
property
¶
The attributes, read-only at every level; empty when the document writes none.
consolidated_metadata
property
¶
The consolidated_metadata member as written, refined, and read-only at every level. UNSET when the document writes none, or writes one that is not an object, which only a scope that leaves the member unclaimed allows.
The documents it lists are not read. Pass the member to
ZarrV3ConsolidatedMetadata to read them all, or read one with
read_node_metadata_v3.
context
property
¶
context: ZarrV3Context
The scope the document was read in. update reads new members in this scope.
extra_fields
property
¶
extra_fields: Mapping[
str,
AcceptedField[GroupExtraFieldDefinition[Any]]
| UnclaimedField,
]
Each member the spec does not define, by key, as the scope read it: an AcceptedField when a definition in scope claims the key (as CORE claims consolidated_metadata), and an UnclaimedField otherwise.
must_understand_fields
property
¶
must_understand_fields: dict[str, ZarrV3ExtensionField]
The extra fields, by key and as written, that no definition in scope reads and that a reader is obligated to understand.
Each unclaimed member of extra_fields not explicitly waived with
must_understand: false (the spec's implicit-true rule, https://github.com/zarr-developers/zarr-specs/blob/fc7dd9c9beb5a50b87f9b08b00bf50fc0048482f/docs/v3/core/index.rst#L1571-L1578). The scope is what
the reader recognizes, so a compliant reader MUST fail to open the
group when this is not empty. The model only reports these fields;
refusing to open is up to the reader.
reading
property
¶
reading: ZarrV3GroupMetadataReading
The document as the scope read it: its extra fields, no problems, and this model.
unclaimed_fields
property
¶
unclaimed_fields: dict[Loc, UnclaimedField]
Every field nothing in scope claims, at any depth, by its location in the document, except an extra member that says "must_understand": false and every field inside it, claimed or not, since a reader may ignore such a member whole.
This answers whether a reader can open the group: the spec requires
a reader to refuse a node with a field it does not understand, and
the scope is what the reader understands. The fields of the
documents that the group's consolidated_metadata lists are not
included, because the group does not read those documents; read
them with consolidated(). The model only reports these fields;
refusing to open is up to the reader.
__eq__ ¶
__init__ ¶
__init__(
document: object, context: ZarrV3Context | None = None
) -> None
Source code in src/zarr_metadata/model/_group_v3.py
__reduce__ ¶
__reduce__() -> tuple[
type[ZarrV3GroupMetadata], tuple[object, ZarrV3Context]
]
consolidated ¶
consolidated() -> ZarrV3ConsolidatedMetadata | None
The documents this group's consolidated_metadata lists, read in this group's own scope; None when the group writes no such member.
A group opens without reading them, so a document with a problem
fails only here. Raises MetadataValidationError with every problem
in them, located in this group's document, under
consolidated_metadata. A consolidated_metadata that is not an
object, which only a scope that leaves it unclaimed opens, is such a
problem too. That includes "consolidated_metadata": null, which
zarr-python 3.0 and 3.1 wrote; read_repaired_node_metadata_v3
removes it.
Source code in src/zarr_metadata/model/_group_v3.py
create_default
classmethod
¶
create_default(
*,
context: ZarrV3Context | None = None,
**overrides: Unpack[ZarrV3GroupMetadataUpdate],
) -> ZarrV3GroupMetadata
Return a group with no attributes, with any document members in overrides applied, read in context. overrides takes what update takes, including UNSET to drop a member and a ZarrV3ConsolidatedMetadata as consolidated_metadata. Raises MetadataValidationError when the resulting document has a problem.
Source code in src/zarr_metadata/model/_group_v3.py
from_json
classmethod
¶
from_json(
data: object, *, context: ZarrV3Context | None = None
) -> ZarrV3GroupMetadata
Return the model of data, a v3 group document read in context.
Raises MetadataValidationError with every problem the read finds.
A consolidated_metadata of null, which zarr-python 3.0 and 3.1
wrote, is a value the document wrote that is not an object. In a
scope that claims the member, as CORE does, this is a problem,
because the spec requires an object. Use
read_repaired_node_metadata_v3 to read such a store. A member the
spec does not define is kept in extra_fields.
Source code in src/zarr_metadata/model/_group_v3.py
from_key_value
classmethod
¶
from_key_value(
mapping: Mapping[StoreKey, bytes],
*,
context: ZarrV3Context | None = None,
) -> ZarrV3GroupMetadata
Return the model of the group document at zarr.json in mapping, read in context.
Raises MetadataValidationError when the key is missing, its bytes
are not JSON, or the document is not valid. Raises TypeError for
a scope of another format before any bytes are decoded.
Source code in src/zarr_metadata/model/_group_v3.py
refined_in ¶
refined_in(
context: ZarrV3Context | None = None,
) -> ZarrV3GroupMetadata
Return this document read in context. context may claim names this scope left unclaimed, but must not contradict any claim.
Raises ScopeConflictError when context reads an extra field with
a different definition, or with no definition, naming each one and
its key. Raises MetadataValidationError when a definition that
context claims rejects what was written under its name. The group
does not read the documents its consolidated_metadata lists, so
this does not check them: consolidated() on the result reads them
in context, and ZarrV3ConsolidatedMetadata.refined_in checks
that they read the same there.
Source code in src/zarr_metadata/model/_group_v3.py
refines ¶
refines(other: ZarrV3GroupMetadata) -> bool
Whether this group holds everything other holds: the same attributes, and the same extra fields, each refining its counterpart in the order refines defines for fields. False when other is not a v3 group.
Source code in src/zarr_metadata/model/_group_v3.py
to_json ¶
to_json() -> ZarrV3GroupMetadataJSON
The document as written, refined. The result shares no objects with the model.
to_key_value ¶
to_key_value(
*, indent: int | str | None = None
) -> Mapping[ZarrV3GroupMetadataStoreKey, bytes]
The document as a store holds it: JSON bytes at zarr.json, indented by indent.
NaN, Infinity and -Infinity in attributes, or in the
documents the consolidated metadata lists, are written as bare
tokens, as zarr-python writes them. A strict JSON parser rejects
these tokens.
Source code in src/zarr_metadata/model/_group_v3.py
update ¶
update(
**members: Unpack[ZarrV3GroupMetadataUpdate],
) -> ZarrV3GroupMetadata
Return this model with members (as JSON) replacing the document's members, read in this model's own scope. A member set to UNSET is removed. A member the spec does not define is given in extra_fields.
A ZarrV3ConsolidatedMetadata given as consolidated_metadata is
read in this model's scope and written as its document. Raises
TypeError for a member the update does not take, and
MetadataValidationError when the resulting document has a
problem, such as a listed model that conflicts with this scope.
Source code in src/zarr_metadata/model/_group_v3.py
with_context ¶
with_context(
context: ZarrV3Context | None = None,
) -> ZarrV3GroupMetadata
Return this document read in context, whatever that changes. Raises MetadataValidationError when the document has a problem in context. The existing reading is reused when context reads every claim identically.
Source code in src/zarr_metadata/model/_group_v3.py
ZarrV3GroupMetadataReading
dataclass
¶
A v3 group document as a scope read it: each extra field, every problem, and the model when there are no problems.
Source code in src/zarr_metadata/model/_group_v3.py
extra_fields
class-attribute
instance-attribute
¶
extra_fields: Mapping[
str, ResolvedField[GroupExtraFieldDefinition[Any]]
] = dataclasses.field(default_factory=no_extra_fields)
Each member the spec does not define, as the scope read it, by key: an UnclaimedField when no definition in scope claims the key.
metadata
class-attribute
instance-attribute
¶
metadata: ZarrV3GroupMetadata | None = None
The document's model when there is no problem; None otherwise.
problems
class-attribute
instance-attribute
¶
problems: tuple[ValidationProblem, ...] = ()
Every reason the document is not valid.
__init__ ¶
__init__(
problems: tuple[ValidationProblem, ...] = (),
metadata: ZarrV3GroupMetadata | None = None,
extra_fields: Mapping[
str, ResolvedField[GroupExtraFieldDefinition[Any]]
] = no_extra_fields(),
) -> None
__reduce__ ¶
Source code in src/zarr_metadata/model/_group_v3.py
ZarrV3GroupMetadataUpdate ¶
Bases: TypedDict
The members ZarrV3GroupMetadata.update replaces: each in the form a document writes it, or UNSET to remove it.
consolidated_metadata is typed as the reference implementation
writes it, or as any JSON object, such as another group's
consolidated_metadata, since a group checks only its envelope. It
can also be a ZarrV3ConsolidatedMetadata: its models are read in the
group's scope, as a listing of node models is read, and its document
is written. A group does not read the documents its consolidated
metadata lists, so build that model to check them before they are
written. Any other member the spec does not define goes in
extra_fields, by key: each one given is set, or removed when given as
UNSET, and the others are kept.
Source code in src/zarr_metadata/model/_group_v3.py
consolidated_metadata
instance-attribute
¶
consolidated_metadata: (
ZarrV3ConsolidatedMetadataJSON
| Mapping[str, JSONValue]
| ZarrV3ConsolidatedMetadata
| UNSET
)
ZarrV3RepairedNodeMetadataReading
dataclass
¶
A v3 zarr.json read after its known writer bugs were undone: the strict reading of the repaired document, and the repairs.
Source code in src/zarr_metadata/model/_repair.py
reading
instance-attribute
¶
reading: ZarrV3NodeMetadataReading
The repaired document, as read_node_metadata_v3 reads it. The problems are those of the repaired document. The model is present when there are no problems.
repairs
instance-attribute
¶
The changes that produced the document that was read.
ZarrV3UnknownNodeMetadataReading
dataclass
¶
A v3 document with no node type the spec defines (its node_type is missing, or is neither "array" nor "group"), or a value that is not an object. Only its zarr_format is read, and the problems report it.
This way, a document in another format is reported as such:
zarr-python 2's draft of v3 wrote a root zarr.json whose
zarr_format is a URL, and a v2 document names format 2.
Source code in src/zarr_metadata/model/_group_v3.py
metadata
property
¶
Its model: always None, since without a node type there is no model to choose.
problems
instance-attribute
¶
problems: tuple[ValidationProblem, ...]
Why the document is not a node.
is_node_name_v3 ¶
Whether value is a v3 node name, meaning validate_node_name_v3 finds no problems.
is_node_path_v3 ¶
Whether value is a v3 node path, meaning validate_node_path_v3 finds no problems.
node_metadata_from_json_v3 ¶
node_metadata_from_json_v3(
data: object, *, context: ZarrV3Context | None = None
) -> ZarrV3NodeMetadata
Return the model of data, a v3 zarr.json read in context, as the node type its node_type declares.
The result is what ZarrV3ArrayMetadata.from_json or
ZarrV3GroupMetadata.from_json returns. This works like pydantic's
TypeAdapter validating a discriminated union. Raises
MetadataValidationError with every problem read_node_metadata_v3
finds, including a node_type that is neither array nor group.
Source code in src/zarr_metadata/model/_group_v3.py
node_metadata_from_key_value_v2 ¶
node_metadata_from_key_value_v2(
mapping: Mapping[StoreKey, bytes],
*,
context: ZarrV2Context | None = None,
) -> ZarrV2NodeMetadata
Return the model of the v2 node whose files are in mapping, a store's keys and bytes: each file is decoded, then read as read_node_metadata_v2 reads it. Raises MetadataValidationError with every problem, including a file whose bytes are not JSON, and TypeError for a scope of another format before any bytes are decoded.
Source code in src/zarr_metadata/model/_group_v2.py
node_metadata_from_key_value_v3 ¶
node_metadata_from_key_value_v3(
mapping: Mapping[StoreKey, bytes],
*,
context: ZarrV3Context | None = None,
) -> ZarrV3NodeMetadata
Return the model of the document at zarr.json in mapping, read in context as the node type its node_type declares, as node_metadata_from_json_v3 reads it.
Raises MetadataValidationError when the key is missing, its bytes
are not JSON, or the document is not a valid array or group.
Source code in src/zarr_metadata/model/_group_v3.py
parse_node_name_v3 ¶
Return value as a NodeName, or raise MetadataValidationError with every reason it is not one.
Source code in src/zarr_metadata/v3/_hierarchy.py
parse_node_path_v3 ¶
Return value as a NodePath, or raise MetadataValidationError with every reason it is not one.
Source code in src/zarr_metadata/v3/_hierarchy.py
read_array_metadata_v2 ¶
read_array_metadata_v2(
value: object, *, context: ZarrV2Context | None = None
) -> ZarrV2ArrayMetadataReading
Read value, a v2 array document, in context (CORE_V2 when none is given), whatever it holds.
The result holds everything the read finds: the dtype, the compressor
and each filter as the scope read them (an AcceptedField read by
the definition that claims the typestr or id, an UnclaimedField, or
a RefusedField), every problem, and, when there are no problems,
the document's model. A dtype or codec that the scope refuses is a
problem. One that the scope does not claim is not a problem.
fill_value is checked against the dtype the scope read.
Source code in src/zarr_metadata/model/_array_v2.py
read_array_metadata_v3 ¶
read_array_metadata_v3(
value: object, *, context: ZarrV3Context | None = None
) -> ZarrV3ArrayMetadataReading
Read value, a v3 array document, in context, whatever it holds.
The result holds everything the read finds: each extension point as
context read it (an AcceptedField read by the definition that
claims its name, an UnclaimedField, or a RefusedField), the chunks
the codecs receive, each codec with the chunk it receives, every
problem, and, when there are no problems, the document's model, which
holds the same reading.
The read checks the structure, and reads each extension point through
the definition that claims its name in context. Examples of
problems: a gzip level out of range, or a key that a codec's
configuration does not declare. The fill value is checked against the
data type as context read it (for example, an int8 fill value of
300). The chunk grid is checked against the shape (for example, a
regular grid with chunk lengths for two dimensions, over an array with
three). The codecs are read as a pipeline, in order, each checked
against the chunk it receives (for example, a transpose whose
order has a different number of axes, or a shard that its inner
chunks do not divide). A shard's inner and index codecs are checked
too. A name that nothing in context claims is not checked, and
neither is a fill value of that data type. After a codec with such a
name, the next codec receives a chunk with unknown shape and data
type. Unknown top-level keys are allowed (they map to
extra_fields). A reader must understand each one that does not
declare must_understand: false; the model reports these as
must_understand_fields.
To apply a policy over the fields (for example, allow only the core
spec's fields), iterate over the reading's fields(). A value that
is not an object has no fields.
Source code in src/zarr_metadata/model/_array_v3.py
read_consolidated_metadata_v2 ¶
read_consolidated_metadata_v2(
value: object, *, context: ZarrV2Context | None = None
) -> ZarrV2ConsolidatedMetadataReading
Read value, a v2 .zmetadata document, in context (CORE_V2 when none is given), whatever it holds: every problem the read finds, and the model when there are none. This is the form of ZarrV2ConsolidatedMetadata(value, context) that returns problems instead of raising them.
Source code in src/zarr_metadata/model/_group_v2.py
read_consolidated_metadata_v3 ¶
read_consolidated_metadata_v3(
value: object, *, context: ZarrV3Context | None = None
) -> ZarrV3ConsolidatedMetadataReading
Read value, a group's consolidated_metadata member, in context (CORE_AND_EXTENSIONS when none is given), whatever it holds: every problem the read finds, and the model when there are none. This is the form of ZarrV3ConsolidatedMetadata(value, context) that returns problems instead of raising them.
Source code in src/zarr_metadata/model/_group_v3.py
read_group_metadata_v2 ¶
read_group_metadata_v2(
value: object, *, context: ZarrV2Context | None = None
) -> ZarrV2GroupMetadataReading
Read value, a v2 group document in the merged form (.zgroup plus attributes from .zattrs), in context (CORE_V2 when none is given), whatever it holds: every problem, and the model when there are none. A group has no fields for a scope to read; context is taken for consistency with every other v2 reader.
Source code in src/zarr_metadata/model/_group_v2.py
read_group_metadata_v3 ¶
read_group_metadata_v3(
value: object, *, context: ZarrV3Context | None = None
) -> ZarrV3GroupMetadataReading
Read value, a v3 group document, in context, whatever it holds: every problem, and the model when there are none.
Unknown top-level keys are allowed (they map to extra_fields). A
reader must understand each one that does not declare
must_understand: false; the model reports these as
must_understand_fields. A consolidated_metadata member, if
present and claimed by the scope, as CORE claims it, is checked
against the envelope the core spec fixes. The documents it lists are
not read; read_consolidated_metadata_v3 reads them. This is the
form of ZarrV3GroupMetadata(value, context) that returns problems
instead of raising them.
Source code in src/zarr_metadata/model/_group_v3.py
read_node_metadata_v2 ¶
read_node_metadata_v2(
files: Mapping[str, object],
*,
context: ZarrV2Context | None = None,
) -> ZarrV2NodeMetadataReading
Read the v2 node described by files, in context (CORE_V2 when none is given), as the node type its files declare.
files maps each of the node's files to its decoded JSON: .zarray
or .zgroup, and .zattrs when there is one. They can come from a
store, decoded (as node_metadata_from_key_value_v2 does), or from the
entries of a .zmetadata, which hold the same JSON. A v2 document
does not name its node type; the file does. A .zarray makes the node
an array, read as read_array_metadata_v2 reads it, and a .zgroup
makes it a group, read as read_group_metadata_v2 reads it, with the
attributes at .zattrs in either case. files with neither, or with
both, give a ZarrV2UnknownNodeMetadataReading with the problem. A
.zarray or .zgroup that writes attributes itself gives the
reading of its node type with no model, and with that problem
followed by the problems of the rest of the file. This is the
v2 counterpart of read_node_metadata_v3, which reads one zarr.json
and its node_type.
Source code in src/zarr_metadata/model/_group_v2.py
read_node_metadata_v3 ¶
read_node_metadata_v3(
value: object, *, context: ZarrV3Context | None = None
) -> ZarrV3NodeMetadataReading
Read value, a v3 zarr.json, in context as the node type its node_type declares.
The node type is the tag of a union, like pydantic's discriminator
and zod's discriminated union. An array is read by
read_array_metadata_v3, and a group by read_group_metadata_v3. A
document that declares neither, or a value that is not an object,
gives a ZarrV3UnknownNodeMetadataReading with the problems,
including any problem with its zarr_format. So no caller has to
read node_type from unvalidated JSON, and a document in another
format is reported as not v3.
Source code in src/zarr_metadata/model/_group_v3.py
read_repaired_consolidated_metadata_v2 ¶
read_repaired_consolidated_metadata_v2(
value: object, *, context: ZarrV2Context | None = None
) -> ZarrV2RepairedConsolidatedMetadataReading
Read value, a v2 .zmetadata, in context as read_consolidated_metadata_v2 does, after repair_consolidated_metadata_v2 has undone each known writer bug in it.
Use this to read stores that other writers made. A caller requests
repairs by calling this function instead of
read_consolidated_metadata_v2. Content that no repair applies to is
read as it is, and reported the same way
read_consolidated_metadata_v2 reports it.
Source code in src/zarr_metadata/model/_repair.py
read_repaired_node_metadata_v2 ¶
read_repaired_node_metadata_v2(
files: Mapping[str, object],
*,
context: ZarrV2Context | None = None,
) -> ZarrV2RepairedNodeMetadataReading
Read files, a v2 node's files, in context as read_node_metadata_v2 does, after repair_node_metadata_v2 has undone each known writer bug in them.
Use this to read stores that other writers made. A caller requests
repairs by calling this function instead of read_node_metadata_v2.
Content that no repair applies to is read as it is, and reported the
same way read_node_metadata_v2 reports it.
Source code in src/zarr_metadata/model/_repair.py
read_repaired_node_metadata_v3 ¶
read_repaired_node_metadata_v3(
value: object, *, context: ZarrV3Context | None = None
) -> ZarrV3RepairedNodeMetadataReading
Read value, a v3 zarr.json, in context as read_node_metadata_v3 does, after repair_node_metadata_v3 has undone each known writer bug in it.
Use this to read stores that other writers made. A caller requests
repairs by calling this function instead of read_node_metadata_v3.
Content that no repair applies to is read as it is, and reported the
same way read_node_metadata_v3 reports it.
Source code in src/zarr_metadata/model/_repair.py
repair_consolidated_metadata_v2 ¶
Undo each known writer bug in value, a v2 .zmetadata, and return the result with the list of changes.
zarr-python 3.x writes a consolidated_metadata member into each
.zgroup entry below the root. This function removes it. The root's
entry is left alone, since no writer puts the member there. Each
.zarray entry is repaired as repair_node_metadata_v2 repairs a
.zarray. Content that no repair applies to is left as it is, and
value is not modified. A document with none of the bugs is returned
as it is, with no repairs.
Source code in src/zarr_metadata/model/_repair.py
repair_node_metadata_v2 ¶
repair_node_metadata_v2(
files: Mapping[str, object],
) -> tuple[Mapping[str, object], tuple[Repair, ...]]
Undo each known writer bug in files, a v2 node's files as read_node_metadata_v2 takes them, and return the result with the list of changes.
zarr-python 3.0.0 to 3.0.6 wrote a non-finite fill value in a
.zarray as a bare token, NaN, which Python's json module reads as
a float. This function writes it as the string the v2 spec uses,
"NaN", and does the same for each component of a complex fill value.
Each repair is located in files, under the name of the file. Content
that no repair applies to is left as it is, and files is not
modified. Files with none of the bugs are returned as they are, with
no repairs.
Source code in src/zarr_metadata/model/_repair.py
repair_node_metadata_v3 ¶
Undo each known writer bug in value, a v3 zarr.json, and return the result with the list of changes.
Each document in the consolidated metadata is repaired too. A group
does not read those documents, but ZarrV3ConsolidatedMetadata reads
them from the repaired group's member. Content that no repair applies
to is left as it is. value is not modified: a repaired document is a
new object, which shares its unchanged parts with value. A document
with none of the bugs is returned as it is, with no repairs.
Source code in src/zarr_metadata/model/_repair.py
validate_node_name_v3 ¶
validate_node_name_v3(
value: object,
) -> tuple[ValidationProblem, ...]
Every reason value is not a v3 node name, reported in one invalid_value problem, or an invalid_type problem if value is not a string.
Source code in src/zarr_metadata/v3/_hierarchy.py
validate_node_path_v3 ¶
validate_node_path_v3(
value: object,
) -> tuple[ValidationProblem, ...]
Every reason value is not a v3 node path, reported in one invalid_value problem, or an invalid_type problem if value is not a string.