1
1
from __future__ import annotations
2
2
3
+ import asyncio
3
4
from dataclasses import dataclass , replace
4
5
from functools import cached_property
5
6
import math
17
18
raise ImportError ("zarr 3.0.0 or later is required to use the numcodecs zarr integration." )
18
19
19
20
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 (
23
25
JSON ,
24
26
parse_named_configuration ,
25
27
product ,
26
- to_thread ,
27
28
)
28
- from zarr .metadata import ArrayMetadata
29
+ from zarr .core . metadata import ArrayMetadata
29
30
30
31
31
32
CODEC_PREFIX = "numcodecs."
@@ -90,7 +91,7 @@ def __init__(self, *, codec_id: str, codec_config: dict[str, JSON]) -> None:
90
91
super ().__init__ (codec_id = codec_id , codec_config = codec_config )
91
92
92
93
async def _decode_single (self , chunk_bytes : Buffer , chunk_spec : ArraySpec ) -> Buffer :
93
- return await to_thread (
94
+ return await asyncio . to_thread (
94
95
as_numpy_array_wrapper ,
95
96
self ._codec .decode ,
96
97
chunk_bytes ,
@@ -104,7 +105,7 @@ def _encode(self, chunk_bytes: Buffer, prototype: BufferPrototype) -> Buffer:
104
105
return prototype .buffer .from_bytes (encoded )
105
106
106
107
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 )
108
109
109
110
110
111
class NumcodecsArrayArrayCodec (NumcodecsCodec , ArrayArrayCodec ):
@@ -113,12 +114,12 @@ def __init__(self, *, codec_id: str, codec_config: dict[str, JSON]) -> None:
113
114
114
115
async def _decode_single (self , chunk_array : NDBuffer , chunk_spec : ArraySpec ) -> NDBuffer :
115
116
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 )
117
118
return chunk_spec .prototype .nd_buffer .from_ndarray_like (out .reshape (chunk_spec .shape ))
118
119
119
120
async def _encode_single (self , chunk_array : NDBuffer , chunk_spec : ArraySpec ) -> NDBuffer :
120
121
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 )
122
123
return chunk_spec .prototype .nd_buffer .from_ndarray_like (out )
123
124
124
125
@@ -128,12 +129,12 @@ def __init__(self, *, codec_id: str, codec_config: dict[str, JSON]) -> None:
128
129
129
130
async def _decode_single (self , chunk_buffer : Buffer , chunk_spec : ArraySpec ) -> NDBuffer :
130
131
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 )
132
133
return chunk_spec .prototype .nd_buffer .from_ndarray_like (out .reshape (chunk_spec .shape ))
133
134
134
135
async def _encode_single (self , chunk_ndbuffer : NDBuffer , chunk_spec : ArraySpec ) -> Buffer :
135
136
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 )
137
138
return chunk_spec .prototype .buffer .from_bytes (out )
138
139
139
140
0 commit comments