Zarr version
v2.18.2
Numcodecs version
v0.13.0
Python Version
3.11
Operating System
Mac
Installation
pip :)
Description
When using an object (specifically a pydantic model) as the fill_value in full, the metadata encoding step fails to encode (pickle) the model. It is instead passed unencoded to the JSON codec which chokes.
Steps to reproduce
from pydantic import BaseModel
import zarr
from numcodecs import Pickle
class MyModel(BaseModel):
x: int
array = zarr.full(
shape=(1,2,3),
fill_value=MyModel(x=1),
dtype=object,
object_codec=Pickle()
)
Additional output
Failure happens in encode_array_metadata where it tries to call json_dumps on
{
'zarr_format': 2,
'shape': (10, 10, 10),
'chunks': (10, 10, 10),
'dtype': '|O',
'compressor': {'id': 'blosc', 'cname': 'lz4', 'clevel': 5, 'shuffle': 1, 'blocksize': 0},
'fill_value': MyModel(x=1),
'order': 'C',
'filters': [{'id': 'pickle', 'protocol': 5}]
}
which, of course, fails :(
(sorry some of my values are different in the meta dict and the example, running this from my tests atm but can reproduce just by running the example)
Zarr version
v2.18.2
Numcodecs version
v0.13.0
Python Version
3.11
Operating System
Mac
Installation
pip :)
Description
When using an object (specifically a pydantic model) as the
fill_valuein full, the metadata encoding step fails to encode (pickle) the model. It is instead passed unencoded to the JSON codec which chokes.Steps to reproduce
Additional output
Failure happens in
encode_array_metadatawhere it tries to calljson_dumpson{ 'zarr_format': 2, 'shape': (10, 10, 10), 'chunks': (10, 10, 10), 'dtype': '|O', 'compressor': {'id': 'blosc', 'cname': 'lz4', 'clevel': 5, 'shuffle': 1, 'blocksize': 0}, 'fill_value': MyModel(x=1), 'order': 'C', 'filters': [{'id': 'pickle', 'protocol': 5}] }which, of course, fails :(
(sorry some of my values are different in the meta dict and the example, running this from my tests atm but can reproduce just by running the example)