Skip to content
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

Sync with zarr 3 beta #597

Merged
Merged
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
3 changes: 2 additions & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,11 @@ jobs:
python -m pip install -v -e .[test,test_extras,msgpack,pcodec]
- name: Install zarr-python
if : matrix.python-version != '3.10'
shell: "bash -l {0}"
run: |
conda activate env
python -m pip install zarr==3.0.0a0
python -m pip install zarr==3.0.0b0
# This is used to test with zfpy, which does not yet support numpy 2.0
- name: Install older numpy and zfpy
Expand Down
23 changes: 12 additions & 11 deletions numcodecs/zarr3.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from __future__ import annotations

import asyncio
from dataclasses import dataclass, replace
from functools import cached_property
import math
Expand All @@ -17,15 +18,15 @@
raise ImportError("zarr 3.0.0 or later is required to use the numcodecs zarr integration.")

from zarr.abc.codec import ArrayArrayCodec, BytesBytesCodec, ArrayBytesCodec
from zarr.buffer import NDBuffer, Buffer, BufferPrototype, as_numpy_array_wrapper
from zarr.array_spec import ArraySpec
from zarr.common import (
from zarr.core.buffer import NDBuffer, Buffer, BufferPrototype
from zarr.core.buffer.cpu import as_numpy_array_wrapper
from zarr.core.array_spec import ArraySpec
from zarr.core.common import (
JSON,
parse_named_configuration,
product,
to_thread,
)
from zarr.metadata import ArrayMetadata
from zarr.core.metadata import ArrayMetadata


CODEC_PREFIX = "numcodecs."
Expand Down Expand Up @@ -90,7 +91,7 @@
super().__init__(codec_id=codec_id, codec_config=codec_config)

async def _decode_single(self, chunk_bytes: Buffer, chunk_spec: ArraySpec) -> Buffer:
return await to_thread(
return await asyncio.to_thread(

Check warning on line 94 in numcodecs/zarr3.py

View check run for this annotation

Codecov / codecov/patch

numcodecs/zarr3.py#L94

Added line #L94 was not covered by tests
as_numpy_array_wrapper,
self._codec.decode,
chunk_bytes,
Expand All @@ -104,7 +105,7 @@
return prototype.buffer.from_bytes(encoded)

async def _encode_single(self, chunk_bytes: Buffer, chunk_spec: ArraySpec) -> Buffer:
return await to_thread(self._encode, chunk_bytes, chunk_spec.prototype)
return await asyncio.to_thread(self._encode, chunk_bytes, chunk_spec.prototype)

Check warning on line 108 in numcodecs/zarr3.py

View check run for this annotation

Codecov / codecov/patch

numcodecs/zarr3.py#L108

Added line #L108 was not covered by tests


class NumcodecsArrayArrayCodec(NumcodecsCodec, ArrayArrayCodec):
Expand All @@ -113,12 +114,12 @@

async def _decode_single(self, chunk_array: NDBuffer, chunk_spec: ArraySpec) -> NDBuffer:
chunk_ndarray = chunk_array.as_ndarray_like()
out = await to_thread(self._codec.decode, chunk_ndarray)
out = await asyncio.to_thread(self._codec.decode, chunk_ndarray)

Check warning on line 117 in numcodecs/zarr3.py

View check run for this annotation

Codecov / codecov/patch

numcodecs/zarr3.py#L117

Added line #L117 was not covered by tests
return chunk_spec.prototype.nd_buffer.from_ndarray_like(out.reshape(chunk_spec.shape))

async def _encode_single(self, chunk_array: NDBuffer, chunk_spec: ArraySpec) -> NDBuffer:
chunk_ndarray = chunk_array.as_ndarray_like()
out = await to_thread(self._codec.encode, chunk_ndarray)
out = await asyncio.to_thread(self._codec.encode, chunk_ndarray)

Check warning on line 122 in numcodecs/zarr3.py

View check run for this annotation

Codecov / codecov/patch

numcodecs/zarr3.py#L122

Added line #L122 was not covered by tests
return chunk_spec.prototype.nd_buffer.from_ndarray_like(out)


Expand All @@ -128,12 +129,12 @@

async def _decode_single(self, chunk_buffer: Buffer, chunk_spec: ArraySpec) -> NDBuffer:
chunk_bytes = chunk_buffer.to_bytes()
out = await to_thread(self._codec.decode, chunk_bytes)
out = await asyncio.to_thread(self._codec.decode, chunk_bytes)

Check warning on line 132 in numcodecs/zarr3.py

View check run for this annotation

Codecov / codecov/patch

numcodecs/zarr3.py#L132

Added line #L132 was not covered by tests
return chunk_spec.prototype.nd_buffer.from_ndarray_like(out.reshape(chunk_spec.shape))

async def _encode_single(self, chunk_ndbuffer: NDBuffer, chunk_spec: ArraySpec) -> Buffer:
chunk_ndarray = chunk_ndbuffer.as_ndarray_like()
out = await to_thread(self._codec.encode, chunk_ndarray)
out = await asyncio.to_thread(self._codec.encode, chunk_ndarray)

Check warning on line 137 in numcodecs/zarr3.py

View check run for this annotation

Codecov / codecov/patch

numcodecs/zarr3.py#L137

Added line #L137 was not covered by tests
return chunk_spec.prototype.buffer.from_bytes(out)


Expand Down
Loading