Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/zarr-metadata/changes/441.doc.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
The `to_json` docstrings and the guide now say what `to_json` returns: a copy in which each JSON array is a tuple, as the package's JSON types spell an array, so it does not compare equal to what `json.loads` returns. They point to comparing models instead. The guide had said `to_json` returns plain containers.
9 changes: 8 additions & 1 deletion packages/zarr-metadata/docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,14 @@ Every typed attribute is a view of that read: each declaration as the scope read
it (an `AcceptedDeclaration` or an `UnclaimedDeclaration`), and `shape`, `attributes`
and the members that hold no declaration as the read refined them. These views are read-only
at every level: a list in the document is shown as a tuple, and an object
as a read-only mapping. `to_json` returns plain containers.
as a read-only mapping. `to_json` returns a copy the caller may change:
each object a new `dict`, and each array a new tuple, since the package's
JSON types spell a JSON array as a tuple. `json.dumps` writes it, but it
does not compare equal to what `json.loads` returns for the same document,
where arrays are lists. To ask whether a model holds a document, compare
models, `ZarrV3ArrayMetadata.from_json(document) == model`, which also
treats a default the document leaves out as equal to the default written
out.

To change a model, call `update`. It replaces members of the document with
the given JSON members and reads the result in the model's own scope, so
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -584,7 +584,7 @@ def reading(self) -> ZarrV2ArrayMetadataReading:
return self._reading

def to_json(self) -> ZarrV2ArrayMetadataJSON:
"""The merged document as written, refined. The result shares no objects with the model.
"""The merged document as written, refined. The result shares no objects with the model. Each JSON array is a tuple, as the package's JSON types spell an array, and each object a new `dict`: `json.dumps` writes the result, but it does not compare equal to what `json.loads` returns. To compare a model with a document, compare models: `from_json(document) == model`.

`attributes` is included when set, even empty. This is not the
on-disk `.zarray`, which excludes them: `to_key_value` splits the
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -581,7 +581,7 @@ def reading(self) -> ZarrV3ArrayMetadataReading:
return self._reading

def to_json(self) -> ZarrV3ArrayMetadataJSON:
"""The document as written, refined. The result shares no objects with the model."""
"""The document as written, refined. The result shares no objects with the model. Each JSON array is a tuple, as the package's JSON types spell an array, and each object a new `dict`: `json.dumps` writes the result, but it does not compare equal to what `json.loads` returns. To compare a model with a document, compare models: `from_json(document) == model`."""
return cast("ZarrV3ArrayMetadataJSON", copied(self._document))

def to_key_value(
Expand Down
4 changes: 2 additions & 2 deletions packages/zarr-metadata/src/zarr_metadata/model/_group_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ def attributes(self) -> Mapping[str, JSONValue]:
return self._shown

def to_json(self) -> ZarrV2GroupMetadataJSON:
"""The merged document as written, refined. The result shares no objects with the model.
"""The merged document as written, refined. The result shares no objects with the model. Each JSON array is a tuple, as the package's JSON types spell an array, and each object a new `dict`: `json.dumps` writes the result, but it does not compare equal to what `json.loads` returns. To compare a model with a document, compare models: `from_json(document) == model`.

`attributes` is included when set, even if empty. This is not the
on-disk `.zgroup`, which excludes them: `to_key_value` splits the
Expand Down Expand Up @@ -546,7 +546,7 @@ def metadata(self) -> Mapping[str, ZarrV2NodeMetadata]:
return MappingProxyType(self._metadata)

def to_json(self) -> dict[str, JSONValue]:
"""The `.zmetadata` document as written, refined. The result shares no objects with the model."""
"""The `.zmetadata` document as written, refined. The result shares no objects with the model. Each JSON array is a tuple, as the package's JSON types spell an array, and each object a new `dict`: `json.dumps` writes the result, but it does not compare equal to what `json.loads` returns. To compare a model with a document, compare models: `from_json(document) == model`."""
return cast("dict[str, JSONValue]", copied(self._document))

def to_key_value(
Expand Down
4 changes: 2 additions & 2 deletions packages/zarr-metadata/src/zarr_metadata/model/_group_v3.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ def reading(self) -> ZarrV3GroupMetadataReading:
return self._reading

def to_json(self) -> ZarrV3GroupMetadataJSON:
"""The document as written, refined. The result shares no objects with the model."""
"""The document as written, refined. The result shares no objects with the model. Each JSON array is a tuple, as the package's JSON types spell an array, and each object a new `dict`: `json.dumps` writes the result, but it does not compare equal to what `json.loads` returns. To compare a model with a document, compare models: `from_json(document) == model`."""
return cast("ZarrV3GroupMetadataJSON", copied(self._document))

def to_key_value(
Expand Down Expand Up @@ -566,7 +566,7 @@ def metadata(self) -> Mapping[str, ZarrV3NodeMetadata]:
return MappingProxyType(self._metadata)

def to_json(self) -> ZarrV3ConsolidatedMetadataJSON:
"""The member as written, refined. The result shares no objects with the model."""
"""The member as written, refined. The result shares no objects with the model. Each JSON array is a tuple, as the package's JSON types spell an array, and each object a new `dict`: `json.dumps` writes the result, but it does not compare equal to what `json.loads` returns. To compare a model with a document, compare models: `from_json(document) == model`."""
return cast("ZarrV3ConsolidatedMetadataJSON", copied(self._document))

def __repr__(self) -> str:
Expand Down
Loading