Skip to content

Commit 9932a1d

Browse files
committed
fixes
1 parent 14807a5 commit 9932a1d

File tree

1 file changed

+18
-12
lines changed

1 file changed

+18
-12
lines changed

numcodecs/zarr3.py

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
import numcodecs
1111

1212
from zarr.abc.codec import ArrayArrayCodec, BytesBytesCodec
13-
from zarr.buffer import NDBuffer, Buffer, as_numpy_array_wrapper
13+
from zarr.buffer import NDBuffer, Buffer, BufferPrototype, as_numpy_array_wrapper
1414
from zarr.array_spec import ArraySpec
1515
from zarr.common import (
1616
JSON,
@@ -64,7 +64,6 @@ def __init__(
6464

6565
@cached_property
6666
def _codec(self) -> numcodecs.abc.Codec:
67-
print(self.codec_config)
6867
return numcodecs.get_codec(self.codec_config)
6968

7069
@classmethod
@@ -92,20 +91,25 @@ def __init__(self, *, codec_id: str, codec_config: dict[str, JSON]) -> None:
9291
super().__init__(codec_id=codec_id, codec_config=codec_config)
9392

9493
async def _decode_single(
95-
self, chunk_bytes: Buffer, _chunk_spec: ArraySpec
94+
self, chunk_bytes: Buffer, chunk_spec: ArraySpec
9695
) -> Buffer:
97-
return await to_thread(as_numpy_array_wrapper, self._codec.decode, chunk_bytes)
96+
return await to_thread(
97+
as_numpy_array_wrapper,
98+
self._codec.decode,
99+
chunk_bytes,
100+
chunk_spec.prototype,
101+
)
98102

99-
def _encode(self, chunk_bytes: Buffer) -> Buffer:
103+
def _encode(self, chunk_bytes: Buffer, prototype: BufferPrototype) -> Buffer:
100104
encoded = self._codec.encode(chunk_bytes.as_array_like())
101105
if isinstance(encoded, np.ndarray): # Required for checksum codecs
102-
return encoded.tobytes()
103-
return Buffer.from_bytes(encoded)
106+
return prototype.buffer.from_bytes(encoded.tobytes())
107+
return prototype.buffer.from_bytes(encoded)
104108

105109
async def _encode_single(
106-
self, chunk_bytes: Buffer, _chunk_spec: ArraySpec
110+
self, chunk_bytes: Buffer, chunk_spec: ArraySpec
107111
) -> Buffer:
108-
return await to_thread(self._encode, chunk_bytes)
112+
return await to_thread(self._encode, chunk_bytes, chunk_spec.prototype)
109113

110114

111115
class NumcodecsArrayArrayCodec(NumcodecsCodec, ArrayArrayCodec):
@@ -117,14 +121,16 @@ async def _decode_single(
117121
) -> NDBuffer:
118122
chunk_ndarray = chunk_array.as_ndarray_like()
119123
out = await to_thread(self._codec.decode, chunk_ndarray)
120-
return NDBuffer.from_ndarray_like(out.reshape(chunk_spec.shape))
124+
return chunk_spec.prototype.nd_buffer.from_ndarray_like(
125+
out.reshape(chunk_spec.shape)
126+
)
121127

122128
async def _encode_single(
123-
self, chunk_array: NDBuffer, _chunk_spec: ArraySpec
129+
self, chunk_array: NDBuffer, chunk_spec: ArraySpec
124130
) -> NDBuffer:
125131
chunk_ndarray = chunk_array.as_ndarray_like()
126132
out = await to_thread(self._codec.encode, chunk_ndarray)
127-
return NDBuffer.from_ndarray_like(out)
133+
return chunk_spec.prototype.nd_buffer.from_ndarray_like(out)
128134

129135

130136
def make_bytes_bytes_codec(

0 commit comments

Comments
 (0)