Skip to content

Commit a4cf7ad

Browse files
authored
Sync with zarr 3 beta (#597)
* Sync with zarr 3 beta * Update zarr version in ci * dont install zarr python 3 in workflows running 3.10
1 parent b75e41e commit a4cf7ad

File tree

2 files changed

+14
-12
lines changed

2 files changed

+14
-12
lines changed

.github/workflows/ci.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,11 @@ jobs:
6464
python -m pip install -v -e .[test,test_extras,msgpack,pcodec]
6565
6666
- name: Install zarr-python
67+
if : matrix.python-version != '3.10'
6768
shell: "bash -l {0}"
6869
run: |
6970
conda activate env
70-
python -m pip install zarr==3.0.0a0
71+
python -m pip install zarr==3.0.0b0
7172
7273
# This is used to test with zfpy, which does not yet support numpy 2.0
7374
- name: Install older numpy and zfpy

numcodecs/zarr3.py

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from __future__ import annotations
22

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

1920
from zarr.abc.codec import ArrayArrayCodec, BytesBytesCodec, ArrayBytesCodec
20-
from zarr.buffer import NDBuffer, Buffer, BufferPrototype, as_numpy_array_wrapper
21-
from zarr.array_spec import ArraySpec
22-
from zarr.common import (
21+
from zarr.core.buffer import NDBuffer, Buffer, BufferPrototype
22+
from zarr.core.buffer.cpu import as_numpy_array_wrapper
23+
from zarr.core.array_spec import ArraySpec
24+
from zarr.core.common import (
2325
JSON,
2426
parse_named_configuration,
2527
product,
26-
to_thread,
2728
)
28-
from zarr.metadata import ArrayMetadata
29+
from zarr.core.metadata import ArrayMetadata
2930

3031

3132
CODEC_PREFIX = "numcodecs."
@@ -90,7 +91,7 @@ def __init__(self, *, codec_id: str, codec_config: dict[str, JSON]) -> None:
9091
super().__init__(codec_id=codec_id, codec_config=codec_config)
9192

9293
async def _decode_single(self, chunk_bytes: Buffer, chunk_spec: ArraySpec) -> Buffer:
93-
return await to_thread(
94+
return await asyncio.to_thread(
9495
as_numpy_array_wrapper,
9596
self._codec.decode,
9697
chunk_bytes,
@@ -104,7 +105,7 @@ def _encode(self, chunk_bytes: Buffer, prototype: BufferPrototype) -> Buffer:
104105
return prototype.buffer.from_bytes(encoded)
105106

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

109110

110111
class NumcodecsArrayArrayCodec(NumcodecsCodec, ArrayArrayCodec):
@@ -113,12 +114,12 @@ def __init__(self, *, codec_id: str, codec_config: dict[str, JSON]) -> None:
113114

114115
async def _decode_single(self, chunk_array: NDBuffer, chunk_spec: ArraySpec) -> NDBuffer:
115116
chunk_ndarray = chunk_array.as_ndarray_like()
116-
out = await to_thread(self._codec.decode, chunk_ndarray)
117+
out = await asyncio.to_thread(self._codec.decode, chunk_ndarray)
117118
return chunk_spec.prototype.nd_buffer.from_ndarray_like(out.reshape(chunk_spec.shape))
118119

119120
async def _encode_single(self, chunk_array: NDBuffer, chunk_spec: ArraySpec) -> NDBuffer:
120121
chunk_ndarray = chunk_array.as_ndarray_like()
121-
out = await to_thread(self._codec.encode, chunk_ndarray)
122+
out = await asyncio.to_thread(self._codec.encode, chunk_ndarray)
122123
return chunk_spec.prototype.nd_buffer.from_ndarray_like(out)
123124

124125

@@ -128,12 +129,12 @@ def __init__(self, *, codec_id: str, codec_config: dict[str, JSON]) -> None:
128129

129130
async def _decode_single(self, chunk_buffer: Buffer, chunk_spec: ArraySpec) -> NDBuffer:
130131
chunk_bytes = chunk_buffer.to_bytes()
131-
out = await to_thread(self._codec.decode, chunk_bytes)
132+
out = await asyncio.to_thread(self._codec.decode, chunk_bytes)
132133
return chunk_spec.prototype.nd_buffer.from_ndarray_like(out.reshape(chunk_spec.shape))
133134

134135
async def _encode_single(self, chunk_ndbuffer: NDBuffer, chunk_spec: ArraySpec) -> Buffer:
135136
chunk_ndarray = chunk_ndbuffer.as_ndarray_like()
136-
out = await to_thread(self._codec.encode, chunk_ndarray)
137+
out = await asyncio.to_thread(self._codec.encode, chunk_ndarray)
137138
return chunk_spec.prototype.buffer.from_bytes(out)
138139

139140

0 commit comments

Comments
 (0)