Skip to content

ensure_bytes for v2 decoders, add pcodec as test dep #3177

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ test = [
"mypy",
"hypothesis",
"pytest-xdist",
"numcodecs[pcodec]"
]
remote_tests = [
'zarr[remote]',
Expand Down
2 changes: 1 addition & 1 deletion src/zarr/codecs/_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
10 changes: 9 additions & 1 deletion tests/test_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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()