Skip to content

do not use array.fill_value when getting the fill value of a zarr array #75

@d-v-b

Description

@d-v-b
# /// script
# requires-python = ">=3.11"
# dependencies = [
#     "pydantic-zarr @ git+https://github.com/zarr-developers/pydantic-zarr.git",
# ]
# ///
from pydantic_zarr.v3 import ArraySpec
import zarr
import numpy as np

z = zarr.create_array(store={}, shape=(10,), dtype='U10')
ArraySpec.from_zarr(z)
pydantic_core._pydantic_core.ValidationError: 6 validation errors for ArraySpec
fill_value.bool
  Input should be a valid boolean, unable to interpret input [type=bool_parsing, input_value=np.str_(''), input_type=str_]
    For further information visit https://errors.pydantic.dev/2.11/v/bool_parsing
fill_value.int
  Input should be a valid integer, unable to parse string as an integer [type=int_parsing, input_value=np.str_(''), input_type=str_]
    For further information visit https://errors.pydantic.dev/2.11/v/int_parsing
fill_value.literal['Infinity','-Infinity','NaN']
  Input should be 'Infinity', '-Infinity' or 'NaN' [type=literal_error, input_value=np.str_(''), input_type=str_]
    For further information visit https://errors.pydantic.dev/2.11/v/literal_error
fill_value.float
  Input should be a valid number, unable to parse string as a number [type=float_parsing, input_value=np.str_(''), input_type=str_]
    For further information visit https://errors.pydantic.dev/2.11/v/float_parsing
fill_value.tuple[union[literal['Infinity','-Infinity','NaN'],float], union[literal['Infinity','-Infinity','NaN'],float]]
  Input should be a valid tuple [type=tuple_type, input_value=np.str_(''), input_type=str_]
    For further information visit https://errors.pydantic.dev/2.11/v/tuple_type
fill_value.`tuple[int, ...]`
  Input should be a valid tuple [type=tuple_type, input_value=np.str_(''), input_type=str_]
    For further information visit https://errors.pydantic.dev/2.11/v/tuple_type

The problem is this line:

fill_value=array.fill_value,

Instead of taking array.fill_value, we need to take the JSON-serializable form, which we can get from meta_json["fill_value"].

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions