From f06beb9b0352ba31c6c6c618dff31d4975a066fe Mon Sep 17 00:00:00 2001 From: Kenneth Li Date: Fri, 27 Jun 2025 15:57:11 -0400 Subject: [PATCH] ensure_bytes for v2 decoders, add pcodec as test dep --- pyproject.toml | 1 + src/zarr/codecs/_v2.py | 2 +- tests/test_v2.py | 10 +++++++++- 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 6c18563a1f..ea9a84d9d4 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -80,6 +80,7 @@ test = [ "mypy", "hypothesis", "pytest-xdist", + "numcodecs[pcodec]" ] remote_tests = [ 'zarr[remote]', diff --git a/src/zarr/codecs/_v2.py b/src/zarr/codecs/_v2.py index 08853f27f1..ca1b042520 100644 --- a/src/zarr/codecs/_v2.py +++ b/src/zarr/codecs/_v2.py @@ -33,7 +33,7 @@ async def _decode_single( cdata = chunk_bytes.as_array_like() # decompress if self.compressor: - chunk = await asyncio.to_thread(self.compressor.decode, cdata) + chunk = await asyncio.to_thread(self.compressor.decode, ensure_bytes(cdata)) else: chunk = cdata diff --git a/tests/test_v2.py b/tests/test_v2.py index 29f031663f..058e9dd3c7 100644 --- a/tests/test_v2.py +++ b/tests/test_v2.py @@ -6,7 +6,7 @@ import numcodecs.vlen import numpy as np import pytest -from numcodecs import Delta +from numcodecs import Delta, PCodec from numcodecs.blosc import Blosc from numcodecs.zstd import Zstd @@ -313,3 +313,11 @@ def test_other_dtype_roundtrip(fill_value: None | bytes, tmp_path: Path) -> None za[...] = a za = zarr.open_array(store=array_path) assert (a == za[:]).all() + + +def test_pcodec_roundtrip(tmp_path: Path) -> None: + array_path = tmp_path / "data.zarr" + z = zarr.create(shape=(3,), store=array_path, chunks=(2,), zarr_format=2, compressor=PCodec()) + z[...] = np.ones(3) + za = zarr.open_array(store=array_path) + assert (za[:] == z).all()