11from __future__ import annotations
22
3+ import asyncio
34from dataclasses import dataclass , replace
45from functools import cached_property
56import math
1718 raise ImportError ("zarr 3.0.0 or later is required to use the numcodecs zarr integration." )
1819
1920from 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
3132CODEC_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
110111class 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