2

Following zarr's tutorial, I'm trying to save a list of list of ints to a persistent zarr:

  • Failed method 1:

    import numcodecs, zarr
    zarr.save("path/to/zarr", [[1], [2]], dtype=object, object_codec=numcodecs.JSON())
    
  • Failed method 2:

    import numcodec, zarr
    z = zarr.array([[1], [2]], dtype=object, object_codec=numcodecs.JSON())
    zarr.save("path/to/zarr", z, dtype=object, object_codec=numcodecs.JSON())
    

Both methods output ValueError: missing object_codec for object array

David Taub
  • 734
  • 1
  • 7
  • 27
  • 1
    maybe related to [this](https://github.com/zarr-developers/zarr-python/issues/691) or [this](https://github.com/fsspec/kerchunk/issues/102) – Helmut Mar 02 '23 at 20:41

1 Answers1

2

I question why you wouldn't just save your list of ints as an array in Zarr. However, it is generally possible to write object dtypes to zarr arrays:

import numpy as np
import zarr
from numcodecs import JSON

# slightly contrived example of an object array
x = np.empty(1, dtype=object)
x[0] = ['foo', 2, 'bar']

za = zarr.open_array('path/to/zarr', shape=x.shape, dtype=object, object_codec=JSON())

print(zarr.open_array(store)[:][0])  # --> ['foo', 2, 'bar']

jhamman
  • 5,867
  • 19
  • 39