From 5625cbe9000d07505c51255f83c36d3acbdd8b10 Mon Sep 17 00:00:00 2001 From: Matthew Iannucci Date: Sat, 12 Oct 2024 10:36:44 -0400 Subject: [PATCH 1/3] Sync with zarr 3 beta --- numcodecs/zarr3.py | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/numcodecs/zarr3.py b/numcodecs/zarr3.py index dd058dfd..05112676 100644 --- a/numcodecs/zarr3.py +++ b/numcodecs/zarr3.py @@ -1,5 +1,6 @@ from __future__ import annotations +import asyncio from dataclasses import dataclass, replace from functools import cached_property import math @@ -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." @@ -90,7 +91,7 @@ def __init__(self, *, codec_id: str, codec_config: dict[str, JSON]) -> None: 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( as_numpy_array_wrapper, self._codec.decode, chunk_bytes, @@ -104,7 +105,7 @@ def _encode(self, chunk_bytes: Buffer, prototype: BufferPrototype) -> Buffer: 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) class NumcodecsArrayArrayCodec(NumcodecsCodec, ArrayArrayCodec): @@ -113,12 +114,12 @@ def __init__(self, *, codec_id: str, codec_config: dict[str, JSON]) -> None: 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) 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) return chunk_spec.prototype.nd_buffer.from_ndarray_like(out) @@ -128,12 +129,12 @@ def __init__(self, *, codec_id: str, codec_config: dict[str, JSON]) -> None: 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) 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) return chunk_spec.prototype.buffer.from_bytes(out) From a895a6c09ab9f74e22b475a59a861f5ab0255280 Mon Sep 17 00:00:00 2001 From: Matthew Iannucci Date: Tue, 15 Oct 2024 14:45:46 -0400 Subject: [PATCH 2/3] Update zarr version in ci --- .github/workflows/ci.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index bb3003b5..c67e23c1 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -67,7 +67,7 @@ jobs: 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 From d01669baff1d4ae213b1a11ef8bb518ec844b416 Mon Sep 17 00:00:00 2001 From: Matthew Iannucci Date: Tue, 15 Oct 2024 16:45:47 -0400 Subject: [PATCH 3/3] dont install zarr python 3 in workflows running 3.10 --- .github/workflows/ci.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index c67e23c1..a7ab815e 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -64,6 +64,7 @@ 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