Skip to content

Commit b6faac6

Browse files
committed
async
1 parent c04d7dc commit b6faac6

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

src/zarr/codecs/_v2.py

Lines changed: 5 additions & 4 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
45
from typing import TYPE_CHECKING
56

@@ -32,14 +33,14 @@ async def _decode_single(
3233
cdata = chunk_bytes.as_array_like()
3334
# decompress
3435
if self.compressor:
35-
chunk = self.compressor.decode(cdata)
36+
chunk = await asyncio.to_thread(self.compressor.decode, cdata)
3637
else:
3738
chunk = cdata
3839

3940
# apply filters
4041
if self.filters:
4142
for f in reversed(self.filters):
42-
chunk = f.decode(chunk)
43+
chunk = await asyncio.to_thread(f.decode, chunk)
4344

4445
# view as numpy array with correct dtype
4546
chunk = ensure_ndarray_like(chunk)
@@ -71,15 +72,15 @@ async def _encode_single(
7172
# apply filters
7273
if self.filters:
7374
for f in self.filters:
74-
chunk = f.encode(chunk)
75+
chunk = await asyncio.to_thread(f.encode, chunk)
7576

7677
# check object encoding
7778
if ensure_ndarray_like(chunk).dtype == object:
7879
raise RuntimeError("cannot write object array without object codec")
7980

8081
# compress
8182
if self.compressor:
82-
cdata = self.compressor.encode(chunk)
83+
cdata = await asyncio.to_thread(self.compressor.encode, chunk)
8384
else:
8485
cdata = chunk
8586

0 commit comments

Comments
 (0)