Skip to content

Commit

Permalink
broken pydantic 2 migration
Browse files Browse the repository at this point in the history
  • Loading branch information
d-v-b committed Oct 27, 2023
1 parent af6282c commit 0e28e17
Show file tree
Hide file tree
Showing 9 changed files with 455 additions and 416 deletions.
2 changes: 1 addition & 1 deletion docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Static typing and runtime validation for Zarr hiearchies.

```python
import zarr
from pydantic_zarr import GroupSpec
from pydantic_zarr.v2 import GroupSpec

group = zarr.group(path='foo')
array = zarr.create(store = group.store, path='foo/bar', shape=10, dtype='uint8')
Expand Down
20 changes: 10 additions & 10 deletions docs/usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Note that `to_zarr` will *not* write any array data. You have to do this separat
from zarr import group
from zarr.creation import create
from zarr.storage import MemoryStore
from pydantic_zarr import GroupSpec
from pydantic_zarr.v2 import GroupSpec

# create an in-memory Zarr group + array with attributes
grp = group(path='foo')
Expand All @@ -29,7 +29,8 @@ arr = create(path='foo/bar', store=grp.store, shape=(10,), compressor=None)
arr.attrs.put({'array_metadata': True})

spec = GroupSpec.from_zarr(grp)
print(spec.dict())
spec_dict = spec.model_dump()
print(spec_dict)
"""
{
'zarr_version': 2,
Expand All @@ -41,7 +42,7 @@ print(spec.dict())
'shape': (10,),
'chunks': (10,),
'dtype': '<f8',
'fill_value': 0,
'fill_value': 0.0,
'order': 'C',
'filters': None,
'dimension_separator': '.',
Expand All @@ -52,11 +53,10 @@ print(spec.dict())
"""

# modify the spec to define a new Zarr hierarchy
spec2 = spec.copy()
spec2.attributes = {'a': 100, 'b': 'metadata'}

spec2.members['bar'].shape = (100,)

spec_dict2 = spec_dict.copy()
spec_dict2['attributes'] = {'a': 100, 'b': 'metadata'}
spec_dict2['members']['bar']['shape'] = [100,]
spec2 = GroupSpec(**spec_dict2)
# serialize the spec to the store
group2 = spec2.to_zarr(grp.store, path='foo2')

Expand All @@ -81,7 +81,7 @@ The `ArraySpec` class has a `from_array` static method that takes a numpy-array-
from pydantic_zarr import ArraySpec
import numpy as np

print(ArraySpec.from_array(np.arange(10)).dict())
print(ArraySpec.from_array(np.arange(10)).model_dump())
"""
{
'zarr_version': 2,
Expand Down Expand Up @@ -156,7 +156,7 @@ members = {'foo': ArraySpec(attributes={},
dtype='uint8',
chunks=(1,),
compressor=None)}
print(ArraysOnlyGroup(attributes={}, members=members).dict())
print(ArraysOnlyGroup(attributes={}, members=members).model_dump())
"""
{
'zarr_version': 2,
Expand Down
1 change: 0 additions & 1 deletion src/pydantic_zarr/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
# ruff: noqa
from pydantic_zarr.core import ArraySpec, GroupSpec, to_zarr, from_zarr
Loading

0 comments on commit 0e28e17

Please sign in to comment.