Skip to content
Merged
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
10 changes: 5 additions & 5 deletions docs/usage_zarr_v2.md
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ from pydantic_zarr.v2 import ArraySpec, GroupSpec
tree = {
"": GroupSpec(members=None, attributes={"root": True}),
"/a": GroupSpec(members=None, attributes={"root": False}),
"/a/b": ArraySpec(shape=(10, 10), dtype="uint8", chunks=(1, 1)),
"/a/b": ArraySpec(shape=(10, 10), dtype="uint8", chunks=(1, 1), attributes={}),
}

print(GroupSpec.from_flat(tree).model_dump())
Expand Down Expand Up @@ -166,7 +166,7 @@ from pydantic_zarr.v2 import ArraySpec, GroupSpec
# the keys must be valid paths in the Zarr storage hierarchy
# note that the `members` attribute is `None` for the `GroupSpec` instances in this `dict`.

a_b = ArraySpec(shape=(10, 10), dtype="uint8", chunks=(1, 1))
a_b = ArraySpec(shape=(10, 10), dtype="uint8", chunks=(1, 1), attributes={})
a = GroupSpec(members={'b': a_b}, attributes={"root": False})
root = GroupSpec(members={'a': a}, attributes={"root": True})

Expand Down Expand Up @@ -200,7 +200,7 @@ hierarchy without explicitly creating the intermediate groups first.
```python
from pydantic_zarr.v2 import ArraySpec, GroupSpec

tree = {'/a/b/c': ArraySpec(shape=(1,), dtype='uint8', chunks=(1,))}
tree = {'/a/b/c': ArraySpec(shape=(1,), dtype='uint8', chunks=(1,), attributes={})}
print(GroupSpec.from_flat(tree).model_dump())
"""
{
Expand Down Expand Up @@ -250,9 +250,9 @@ import zarr.storage

from pydantic_zarr.v2 import ArraySpec, GroupSpec

arr_a = ArraySpec(shape=(1,), dtype='uint8', chunks=(1,))
arr_a = ArraySpec(shape=(1,), dtype='uint8', chunks=(1,), attributes={})
# make an array with a different shape
arr_b = ArraySpec(shape=(2,), dtype='uint8', chunks=(1,))
arr_b = ArraySpec(shape=(2,), dtype='uint8', chunks=(1,), attributes={})

# Returns False, because of mismatched shape
print(arr_a.like(arr_b))
Expand Down
8 changes: 4 additions & 4 deletions src/pydantic_zarr/v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ class ArraySpec(NodeSpec, Generic[TAttr]):

Attributes
----------
attributes: TAttr, default = {}
attributes: TAttr
User-defined metadata associated with this array. Should be JSON-serializable.
shape: tuple[int, ...]
The shape of this array.
Expand All @@ -168,7 +168,7 @@ class ArraySpec(NodeSpec, Generic[TAttr]):
The default is "/".
"""

attributes: TAttr = cast(TAttr, {})
attributes: TAttr
shape: tuple[int, ...]
chunks: tuple[int, ...]
dtype: DtypeStr | list[tuple[Any, ...]]
Expand Down Expand Up @@ -467,7 +467,7 @@ class can be found in the
Attributes
----------

attributes: TAttr, default = {}
attributes: TAttr
The user-defined attributes of this group. Should be JSON-serializable.
members: dict[str, TItem] | None, default = {}
The members of this group. `members` may be `None`, which models the condition
Expand All @@ -476,7 +476,7 @@ class can be found in the
are either `ArraySpec` or `GroupSpec`.
"""

attributes: TAttr = cast(TAttr, {})
attributes: TAttr
members: Annotated[Mapping[str, TItem] | None, AfterValidator(ensure_key_no_path)] = {}

@classmethod
Expand Down
4 changes: 2 additions & 2 deletions src/pydantic_zarr/v3.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ class ArraySpec(NodeSpec, Generic[TAttr]):
"""

node_type: Literal["array"] = "array"
attributes: TAttr = cast(TAttr, {})
attributes: TAttr
shape: tuple[int, ...]
data_type: DTypeLike
chunk_grid: RegularChunking # todo: validate this against shape
Expand Down Expand Up @@ -507,7 +507,7 @@ class GroupSpec(NodeSpec, Generic[TAttr, TItem]):
"""

node_type: Literal["group"] = "group"
attributes: TAttr = cast("TAttr", {})
attributes: TAttr
members: Annotated[Mapping[str, TItem] | None, AfterValidator(ensure_key_no_path)] = {}

@classmethod
Expand Down
2 changes: 1 addition & 1 deletion tests/test_pydantic_zarr/test_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -576,7 +576,7 @@ def test_array_like() -> None:


def test_array_like_with_zarr() -> None:
arr = ArraySpec(shape=(1,), dtype="uint8", chunks=(1,))
arr = ArraySpec(shape=(1,), dtype="uint8", chunks=(1,), attributes={})
store = zarr.storage.MemoryStore()
arr_stored = arr.to_zarr(store, path="arr")
assert arr.like(arr_stored)
Expand Down
1 change: 1 addition & 0 deletions tests/test_pydantic_zarr/test_v3.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ def test_arrayspec_to_zarr(
store = {}

arr_spec = ArraySpec(
attributes={},
shape=(10,),
data_type=data_type,
chunk_grid={"name": "regular", "configuration": {"chunk_shape": (10,)}},
Expand Down
Loading