Skip to content

Commit 6300815

Browse files
authored
Merge pull request #12 from janelia-cellmap/items_to_members
Items to members
2 parents 805dcfd + 5f44eaf commit 6300815

File tree

5 files changed

+282
-62
lines changed

5 files changed

+282
-62
lines changed

docs/index.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ print(spec.dict())
2222
{
2323
'zarr_version': 2,
2424
'attrs': {},
25-
'items': {
25+
'members': {
2626
'bar': {
2727
'zarr_version': 2,
2828
'attrs': {'metadata': 'hello'},
@@ -68,11 +68,11 @@ Note the use of the term "schematized": Zarr arrays also represent N-dimensional
6868
Accordingly, in `pydantic-zarr`, Zarr groups are encoded by the `GroupSpec` class with two fields:
6969

7070
- `GroupSpec.attrs`: either a `Mapping` or a `pydantic.BaseModel`.
71-
- `GroupSpec.items`: a mapping with string keys and values that must be `GroupSpec` or `ArraySpec` instances.
71+
- `GroupSpec.members`: a mapping with string keys and values that must be `GroupSpec` or `ArraySpec` instances.
7272

7373
Zarr arrays are represented by the `ArraySpec` class, which has a similar `attrs` field, as well as fields for all the Zarr array properties (`dtype`, `shape`, `chunks`, etc).
7474

75-
`GroupSpec` and `ArraySpec` are both [generic models](https://docs.pydantic.dev/1.10/usage/models/#generic-models). `GroupSpec` takes two type parameters, the first specializing the type of `GroupSpec.attrs`, and the second specializing the type of the *values* of `GroupSpec.items` (they keys of `GroupSpec.items` are always strings). `ArraySpec` only takes one type parameter, which specializes the type of `ArraySpec.attrs`.
75+
`GroupSpec` and `ArraySpec` are both [generic models](https://docs.pydantic.dev/1.10/usage/models/#generic-models). `GroupSpec` takes two type parameters, the first specializing the type of `GroupSpec.attrs`, and the second specializing the type of the *values* of `GroupSpec.items` (the keys of `GroupSpec.members` are strings). `ArraySpec` only takes one type parameter, which specializes the type of `ArraySpec.attrs`.
7676

7777
Examples using this generic typing functionality can be found in the [usage guide](usage.md#using-generic-types).
7878

docs/usage.md

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ print(spec.dict())
3434
{
3535
'zarr_version': 2,
3636
'attrs': {'group_metadata': 10},
37-
'items': {
37+
'members': {
3838
'bar': {
3939
'zarr_version': 2,
4040
'attrs': {'array_metadata': True},
@@ -55,7 +55,7 @@ print(spec.dict())
5555
spec2 = spec.copy()
5656
spec2.attrs = {'a': 100, 'b': 'metadata'}
5757

58-
spec2.items['bar'].shape = (100,)
58+
spec2.members['bar'].shape = (100,)
5959

6060
# serialize the spec to the store
6161
group2 = spec2.to_zarr(grp.store, path='foo2')
@@ -128,40 +128,40 @@ except ValidationError as exc:
128128

129129
# this passes validation
130130
print(SpecificAttrsGroup(attrs={'a': 100, 'b': 100}))
131-
#> zarr_version=2 attrs={'a': 100, 'b': 100} items={}
131+
#> zarr_version=2 attrs={'a': 100, 'b': 100} members={}
132132

133133
# a Zarr group that only contains arrays -- no subgroups!
134134
# we re-use the TAttrs type variable defined in pydantic_zarr.core
135135
ArraysOnlyGroup = GroupSpec[TAttr, ArraySpec]
136136

137137
try:
138-
ArraysOnlyGroup(attrs={}, items={'foo': GroupSpec(attrs={})})
138+
ArraysOnlyGroup(attrs={}, members={'foo': GroupSpec(attrs={})})
139139
except ValidationError as exc:
140140
print(exc)
141141
"""
142142
4 validation errors for GroupSpec[TAttr, ArraySpec]
143-
items -> foo -> shape
143+
members -> foo -> shape
144144
field required (type=value_error.missing)
145-
items -> foo -> chunks
145+
members -> foo -> chunks
146146
field required (type=value_error.missing)
147-
items -> foo -> dtype
147+
members -> foo -> dtype
148148
field required (type=value_error.missing)
149-
items -> foo -> items
149+
members -> foo -> members
150150
extra fields not permitted (type=value_error.extra)
151151
"""
152152

153153
# this passes validation
154-
items = {'foo': ArraySpec(attrs={},
155-
shape=(1,),
156-
dtype='uint8',
157-
chunks=(1,),
158-
compressor=None)}
159-
print(ArraysOnlyGroup(attrs={}, items=items).dict())
154+
members = {'foo': ArraySpec(attrs={},
155+
shape=(1,),
156+
dtype='uint8',
157+
chunks=(1,),
158+
compressor=None)}
159+
print(ArraysOnlyGroup(attrs={}, members=members).dict())
160160
"""
161161
{
162162
'zarr_version': 2,
163163
'attrs': {},
164-
'items': {
164+
'members': {
165165
'foo': {
166166
'zarr_version': 2,
167167
'attrs': {},

0 commit comments

Comments
 (0)