Skip to content

Commit b2071a7

Browse files
committed
(fix): encode-decode test
1 parent 0b207a7 commit b2071a7

File tree

2 files changed

+15
-6
lines changed

2 files changed

+15
-6
lines changed

src/zarr/core/metadata/v2.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,9 @@ def to_dict(self) -> dict[str, JSON]:
194194

195195
_ = zarray_dict.pop("dtype")
196196
dtype_json: JSON
197-
if self.dtype.kind == "V":
197+
# In the case of zarr v2, the simplest i.e., '|VXX' dtype is represented as a string
198+
dtype_descr = self.dtype.descr
199+
if self.dtype.kind == "V" and dtype_descr[0][0] != "" and len(dtype_descr) != 0:
198200
dtype_json = tuple(self.dtype.descr)
199201
else:
200202
dtype_json = self.dtype.str

tests/test_v2.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,15 @@ def test_codec_pipeline() -> None:
8282
np.testing.assert_array_equal(result, expected)
8383

8484

85-
@pytest.mark.parametrize("dtype", ["|S", "|V"])
86-
async def test_v2_encode_decode(dtype):
85+
@pytest.mark.parametrize(
86+
("dtype", "expected_dtype", "fill_value", "fill_value_encoding"),
87+
[
88+
("|S", "|S0", b"X", "WA=="),
89+
("|V", "|V0", b"X", "WA=="),
90+
("|V10", "|V10", b"X", "WAAAAAAAAAAAAA=="),
91+
],
92+
)
93+
async def test_v2_encode_decode(dtype, expected_dtype, fill_value, fill_value_encoding) -> None:
8794
with config.set(
8895
{
8996
"array.v2_default_filters.bytes": [{"id": "vlen-bytes"}],
@@ -97,7 +104,7 @@ async def test_v2_encode_decode(dtype):
97104
shape=(3,),
98105
chunks=(3,),
99106
dtype=dtype,
100-
fill_value=b"X",
107+
fill_value=fill_value,
101108
)
102109

103110
result = await store.get("foo/.zarray", zarr.core.buffer.default_buffer_prototype())
@@ -107,8 +114,8 @@ async def test_v2_encode_decode(dtype):
107114
expected = {
108115
"chunks": [3],
109116
"compressor": None,
110-
"dtype": f"{dtype}0",
111-
"fill_value": "WA==",
117+
"dtype": expected_dtype,
118+
"fill_value": fill_value_encoding,
112119
"filters": [{"id": "vlen-bytes"}] if dtype == "|S" else None,
113120
"order": "C",
114121
"shape": [3],

0 commit comments

Comments
 (0)