Skip to content

Conversation

@d-v-b
Copy link
Collaborator

@d-v-b d-v-b commented Dec 12, 2025

2 fixes in this PR:

  • removes the default attributes for v3 arrayspec
  • allows from_zarr to work by constructing the final group from dicts instead of arrayspec / groupspec instances

result: GroupSpec
attributes = group.attrs.asdict()
members: dict[str, object] = {}
members: dict[str, dict[str, object]] = {}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this not be dict[str, GroupSpec | ArraySpec], and pydantic will handle the casting if it's given dict[str, object] as input?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we are filling members with dicts produced by ArraySpec.model_dump() / GroupSpec.model_dump(). If we don't do that, then pydantic will reject models that declared specialized members, because pydantic uses nominal typing (isinstance checks) when the input is a basemodel

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Won't the specialised members be sub-classes of ArraySpec or GroupSpec though, and therefore would pass the isinstance check?

Copy link
Collaborator Author

@d-v-b d-v-b Dec 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is what will happen:

from pydantic_zarr.experimental.v3 import ArraySpec, GroupSpec
import numpy as np

class MyArray(ArraySpec):
    ...

class MyGroup(GroupSpec):
    members: dict[str, MyArray]

MyGroup(attributes={},members={'a': ArraySpec.from_array(np.arange(10))})
"""
pydantic_core._pydantic_core.ValidationError: 1 validation error for MyGroup
members.a
  Input should be a valid dictionary or instance of MyArray [type=model_type, input_value=ArraySpec(zarr_format=3, ...), dimension_names=None), input_type=ArraySpec]
    For further information visit https://errors.pydantic.dev/2.11/v/model_type
"""

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isinstance(ArraySpec(...), SpecializedArraySpec) will fail, which is why we need to turn the arrayspec / groupspec members into dicts

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay - sorry, this is somewhat off-topic on this PR

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no worries!

@d-v-b d-v-b merged commit 31f88cf into zarr-developers:main Dec 12, 2025
14 checks passed
@d-v-b d-v-b deleted the fix/deserialize-in-one-place branch December 12, 2025 15:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants