Skip to content

Commit

Permalink
Set object codec for object arrays
Browse files Browse the repository at this point in the history
  • Loading branch information
tomwhite committed Sep 12, 2024
1 parent 88ae813 commit 5d65121
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
10 changes: 10 additions & 0 deletions cubed/storage/backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,16 @@ def open_backend_array(
from cubed.storage.backends.zarr_python import open_zarr_array

open_func = open_zarr_array

import numpy as np

if np.dtype(dtype).hasobject:
import numcodecs

object_codec = numcodecs.Pickle()
if "object_codec" not in kwargs:
kwargs["object_codec"] = object_codec

elif storage_name == "zarr-python-v3":
from cubed.storage.backends.zarr_python_v3 import open_zarr_v3_array

Expand Down
6 changes: 6 additions & 0 deletions cubed/tests/test_types.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from numpy.testing import assert_array_equal

import cubed
import cubed.array_api as xp


Expand All @@ -8,3 +9,8 @@ def test_prod_sum_bool():
a = xp.ones((2,), dtype=xp.bool)
assert_array_equal(xp.prod(a).compute(), xp.asarray([1], dtype=xp.int64))
assert_array_equal(xp.sum(a).compute(), xp.asarray([2], dtype=xp.int64))


def test_object_dtype():
a = xp.asarray(["a", "b"], dtype=object, chunks=2)
cubed.to_zarr(a, store=None)

0 comments on commit 5d65121

Please sign in to comment.