Skip to content

Commit 509a5c1

Browse files
committed
maybe fixed
1 parent 9603b0e commit 509a5c1

2 files changed

Lines changed: 5 additions & 2 deletions

File tree

src/zarr/codecs/_v2.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ async def _decode_single(
3636
chunk_numpy_array = ensure_ndarray(chunk_bytes.as_array_like())
3737

3838
# ensure correct dtype
39-
if str(chunk_numpy_array.dtype) != chunk_spec.dtype:
39+
if str(chunk_numpy_array.dtype) != chunk_spec.dtype and not chunk_spec.dtype.hasobject:
4040
chunk_numpy_array = chunk_numpy_array.view(chunk_spec.dtype)
4141

4242
return get_ndbuffer_class().from_numpy_array(chunk_numpy_array)

tests/v3/test_v2.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,10 @@ async def test_v2_encode_decode(dtype):
116116

117117
@pytest.mark.parametrize("dtype", [str, "str"])
118118
async def test_create_dtype_str(dtype: Any) -> None:
119-
arr = zarr.create(shape=10, dtype=dtype, zarr_format=2)
119+
arr = zarr.create(shape=3, dtype=dtype, zarr_format=2)
120120
assert arr.dtype.kind == "O"
121121
assert arr.metadata.to_dict()["dtype"] == "|O"
122122
assert arr.metadata.filters == (numcodecs.vlen.VLenUTF8(),)
123+
arr[:] = ["a", "bb", "ccc"]
124+
result = arr[:]
125+
np.testing.assert_array_equal(result, np.array(["a", "bb", "ccc"], dtype="object"))

0 commit comments

Comments
 (0)