Skip to content

Commit 960c885

Browse files
committed
chunk_metadata -> chunk_spec
1 parent 36f1625 commit 960c885

File tree

11 files changed

+106
-108
lines changed

11 files changed

+106
-108
lines changed

zarr/v3/abc/codec.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,11 @@ def from_metadata(cls, codec_metadata: CodecMetadata) -> Codec:
3333
pass
3434

3535
@abstractmethod
36-
def compute_encoded_size(self, input_byte_length: int, chunk_metadata: ArraySpec) -> int:
36+
def compute_encoded_size(self, input_byte_length: int, chunk_spec: ArraySpec) -> int:
3737
pass
3838

39-
def resolve_metadata(self, chunk_metadata: ArraySpec) -> ArraySpec:
40-
return chunk_metadata
39+
def resolve_metadata(self, chunk_spec: ArraySpec) -> ArraySpec:
40+
return chunk_spec
4141

4242
def evolve(self, *, ndim: int, data_type: DataType) -> Codec:
4343
return self
@@ -51,7 +51,7 @@ class ArrayArrayCodec(Codec):
5151
async def decode(
5252
self,
5353
chunk_array: np.ndarray,
54-
chunk_metadata: ArraySpec,
54+
chunk_spec: ArraySpec,
5555
runtime_configuration: RuntimeConfiguration,
5656
) -> np.ndarray:
5757
pass
@@ -60,7 +60,7 @@ async def decode(
6060
async def encode(
6161
self,
6262
chunk_array: np.ndarray,
63-
chunk_metadata: ArraySpec,
63+
chunk_spec: ArraySpec,
6464
runtime_configuration: RuntimeConfiguration,
6565
) -> Optional[np.ndarray]:
6666
pass
@@ -71,7 +71,7 @@ class ArrayBytesCodec(Codec):
7171
async def decode(
7272
self,
7373
chunk_array: BytesLike,
74-
chunk_metadata: ArraySpec,
74+
chunk_spec: ArraySpec,
7575
runtime_configuration: RuntimeConfiguration,
7676
) -> np.ndarray:
7777
pass
@@ -80,7 +80,7 @@ async def decode(
8080
async def encode(
8181
self,
8282
chunk_array: np.ndarray,
83-
chunk_metadata: ArraySpec,
83+
chunk_spec: ArraySpec,
8484
runtime_configuration: RuntimeConfiguration,
8585
) -> Optional[BytesLike]:
8686
pass
@@ -92,7 +92,7 @@ async def decode_partial(
9292
self,
9393
store_path: StorePath,
9494
selection: SliceSelection,
95-
chunk_metadata: ArraySpec,
95+
chunk_spec: ArraySpec,
9696
runtime_configuration: RuntimeConfiguration,
9797
) -> Optional[np.ndarray]:
9898
pass
@@ -105,7 +105,7 @@ async def encode_partial(
105105
store_path: StorePath,
106106
chunk_array: np.ndarray,
107107
selection: SliceSelection,
108-
chunk_metadata: ArraySpec,
108+
chunk_spec: ArraySpec,
109109
runtime_configuration: RuntimeConfiguration,
110110
) -> None:
111111
pass
@@ -116,7 +116,7 @@ class BytesBytesCodec(Codec):
116116
async def decode(
117117
self,
118118
chunk_array: BytesLike,
119-
chunk_metadata: ArraySpec,
119+
chunk_spec: ArraySpec,
120120
runtime_configuration: RuntimeConfiguration,
121121
) -> BytesLike:
122122
pass
@@ -125,7 +125,7 @@ async def decode(
125125
async def encode(
126126
self,
127127
chunk_array: BytesLike,
128-
chunk_metadata: ArraySpec,
128+
chunk_spec: ArraySpec,
129129
runtime_configuration: RuntimeConfiguration,
130130
) -> Optional[BytesLike]:
131131
pass

zarr/v3/array.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -257,14 +257,14 @@ async def _read_chunk(
257257
out_selection: SliceSelection,
258258
out: np.ndarray,
259259
):
260-
chunk_metadata = self.metadata.get_chunk_metadata(chunk_coords)
260+
chunk_spec = self.metadata.get_chunk_spec(chunk_coords)
261261
chunk_key_encoding = self.metadata.chunk_key_encoding
262262
chunk_key = chunk_key_encoding.encode_chunk_key(chunk_coords)
263263
store_path = self.store_path / chunk_key
264264

265265
if self.codec_pipeline.supports_partial_decode:
266266
chunk_array = await self.codec_pipeline.decode_partial(
267-
store_path, chunk_selection, chunk_metadata, self.runtime_configuration
267+
store_path, chunk_selection, chunk_spec, self.runtime_configuration
268268
)
269269
if chunk_array is not None:
270270
out[out_selection] = chunk_array
@@ -274,7 +274,7 @@ async def _read_chunk(
274274
chunk_bytes = await store_path.get_async()
275275
if chunk_bytes is not None:
276276
chunk_array = await self.codec_pipeline.decode(
277-
chunk_bytes, chunk_metadata, self.runtime_configuration
277+
chunk_bytes, chunk_spec, self.runtime_configuration
278278
)
279279
tmp = chunk_array[chunk_selection]
280280
out[out_selection] = tmp
@@ -326,7 +326,7 @@ async def _write_chunk(
326326
chunk_selection: SliceSelection,
327327
out_selection: SliceSelection,
328328
):
329-
chunk_metadata = self.metadata.get_chunk_metadata(chunk_coords)
329+
chunk_spec = self.metadata.get_array_spec(chunk_coords)
330330
chunk_key_encoding = self.metadata.chunk_key_encoding
331331
chunk_key = chunk_key_encoding.encode_chunk_key(chunk_coords)
332332
store_path = self.store_path / chunk_key
@@ -341,15 +341,15 @@ async def _write_chunk(
341341
chunk_array.fill(value)
342342
else:
343343
chunk_array = value[out_selection]
344-
await self._write_chunk_to_store(store_path, chunk_array, chunk_metadata)
344+
await self._write_chunk_to_store(store_path, chunk_array, chunk_spec)
345345

346346
elif self.codec_pipeline.supports_partial_encode:
347347
# print("encode_partial", chunk_coords, chunk_selection, repr(self))
348348
await self.codec_pipeline.encode_partial(
349349
store_path,
350350
value[out_selection],
351351
chunk_selection,
352-
chunk_metadata,
352+
chunk_spec,
353353
self.runtime_configuration,
354354
)
355355
else:
@@ -367,22 +367,22 @@ async def _write_chunk(
367367
else:
368368
chunk_array = (
369369
await self.codec_pipeline.decode(
370-
chunk_bytes, chunk_metadata, self.runtime_configuration
370+
chunk_bytes, chunk_spec, self.runtime_configuration
371371
)
372372
).copy() # make a writable copy
373373
chunk_array[chunk_selection] = value[out_selection]
374374

375-
await self._write_chunk_to_store(store_path, chunk_array, chunk_metadata)
375+
await self._write_chunk_to_store(store_path, chunk_array, chunk_spec)
376376

377377
async def _write_chunk_to_store(
378-
self, store_path: StorePath, chunk_array: np.ndarray, chunk_metadata: ArraySpec
378+
self, store_path: StorePath, chunk_array: np.ndarray, chunk_spec: ArraySpec
379379
):
380380
if np.all(chunk_array == self.metadata.fill_value):
381381
# chunks that only contain fill_value will be removed
382382
await store_path.delete_async()
383383
else:
384384
chunk_bytes = await self.codec_pipeline.encode(
385-
chunk_array, chunk_metadata, self.runtime_configuration
385+
chunk_array, chunk_spec, self.runtime_configuration
386386
)
387387
if chunk_bytes is None:
388388
await store_path.delete_async()

zarr/v3/codecs/__init__.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ def supports_partial_encode(self) -> bool:
115115
self.array_bytes_codec, ArrayBytesCodecPartialEncodeMixin
116116
)
117117

118-
def all_codecs(self) -> Iterator[Codec]:
118+
def __iter__(self) -> Iterator[Codec]:
119119
for aa_codec in self.array_array_codecs:
120120
yield aa_codec
121121

@@ -125,7 +125,7 @@ def all_codecs(self) -> Iterator[Codec]:
125125
yield bb_codec
126126

127127
def validate(self, array_metadata: ArrayMetadata) -> None:
128-
for codec in self.all_codecs():
128+
for codec in self:
129129
codec.validate(array_metadata)
130130

131131
def _codecs_with_resolved_metadata(
@@ -177,13 +177,13 @@ async def decode_partial(
177177
self,
178178
store_path: StorePath,
179179
selection: SliceSelection,
180-
chunk_metadata: ArraySpec,
180+
chunk_spec: ArraySpec,
181181
runtime_configuration: RuntimeConfiguration,
182182
) -> Optional[np.ndarray]:
183183
assert self.supports_partial_decode
184184
assert isinstance(self.array_bytes_codec, ArrayBytesCodecPartialDecodeMixin)
185185
return await self.array_bytes_codec.decode_partial(
186-
store_path, selection, chunk_metadata, runtime_configuration
186+
store_path, selection, chunk_spec, runtime_configuration
187187
)
188188

189189
async def encode(
@@ -227,17 +227,17 @@ async def encode_partial(
227227
store_path: StorePath,
228228
chunk_array: np.ndarray,
229229
selection: SliceSelection,
230-
chunk_metadata: ArraySpec,
230+
chunk_spec: ArraySpec,
231231
runtime_configuration: RuntimeConfiguration,
232232
) -> None:
233233
assert self.supports_partial_encode
234234
assert isinstance(self.array_bytes_codec, ArrayBytesCodecPartialEncodeMixin)
235235
await self.array_bytes_codec.encode_partial(
236-
store_path, chunk_array, selection, chunk_metadata, runtime_configuration
236+
store_path, chunk_array, selection, chunk_spec, runtime_configuration
237237
)
238238

239239
def compute_encoded_size(self, byte_length: int, array_spec: ArraySpec) -> int:
240-
for codec in self.all_codecs():
240+
for codec in self:
241241
byte_length = codec.compute_encoded_size(byte_length, array_spec)
242242
array_spec = codec.resolve_metadata(array_spec)
243243
return byte_length

zarr/v3/codecs/blosc.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,21 +86,21 @@ def get_blosc_codec(self) -> Blosc:
8686
async def decode(
8787
self,
8888
chunk_bytes: bytes,
89-
_chunk_metadata: ArraySpec,
89+
_chunk_spec: ArraySpec,
9090
_runtime_configuration: RuntimeConfiguration,
9191
) -> BytesLike:
9292
return await to_thread(self.get_blosc_codec().decode, chunk_bytes)
9393

9494
async def encode(
9595
self,
9696
chunk_bytes: bytes,
97-
chunk_metadata: ArraySpec,
97+
chunk_spec: ArraySpec,
9898
_runtime_configuration: RuntimeConfiguration,
9999
) -> Optional[BytesLike]:
100-
chunk_array = np.frombuffer(chunk_bytes, dtype=chunk_metadata.dtype)
100+
chunk_array = np.frombuffer(chunk_bytes, dtype=chunk_spec.dtype)
101101
return await to_thread(self.get_blosc_codec().encode, chunk_array)
102102

103-
def compute_encoded_size(self, _input_byte_length: int, _chunk_metadata: ArraySpec) -> int:
103+
def compute_encoded_size(self, _input_byte_length: int, _chunk_spec: ArraySpec) -> int:
104104
raise NotImplementedError
105105

106106

zarr/v3/codecs/bytes.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -64,30 +64,30 @@ def _get_byteorder(self, array: np.ndarray) -> Endian:
6464
async def decode(
6565
self,
6666
chunk_bytes: BytesLike,
67-
chunk_metadata: ArraySpec,
67+
chunk_spec: ArraySpec,
6868
_runtime_configuration: RuntimeConfiguration,
6969
) -> np.ndarray:
70-
if chunk_metadata.dtype.itemsize > 0:
70+
if chunk_spec.dtype.itemsize > 0:
7171
if self.configuration.endian == "little":
7272
prefix = "<"
7373
else:
7474
prefix = ">"
75-
dtype = np.dtype(f"{prefix}{chunk_metadata.data_type.to_numpy_shortname()}")
75+
dtype = np.dtype(f"{prefix}{chunk_spec.data_type.to_numpy_shortname()}")
7676
else:
77-
dtype = np.dtype(f"|{chunk_metadata.data_type.to_numpy_shortname()}")
77+
dtype = np.dtype(f"|{chunk_spec.data_type.to_numpy_shortname()}")
7878
chunk_array = np.frombuffer(chunk_bytes, dtype)
7979

8080
# ensure correct chunk shape
81-
if chunk_array.shape != chunk_metadata.chunk_shape:
81+
if chunk_array.shape != chunk_spec.shape:
8282
chunk_array = chunk_array.reshape(
83-
chunk_metadata.chunk_shape,
83+
chunk_spec.shape,
8484
)
8585
return chunk_array
8686

8787
async def encode(
8888
self,
8989
chunk_array: np.ndarray,
90-
_chunk_metadata: ArraySpec,
90+
_chunk_spec: ArraySpec,
9191
_runtime_configuration: RuntimeConfiguration,
9292
) -> Optional[BytesLike]:
9393
if chunk_array.dtype.itemsize > 1:
@@ -97,7 +97,7 @@ async def encode(
9797
chunk_array = chunk_array.astype(new_dtype)
9898
return chunk_array.tobytes()
9999

100-
def compute_encoded_size(self, input_byte_length: int, _chunk_metadata: ArraySpec) -> int:
100+
def compute_encoded_size(self, input_byte_length: int, _chunk_spec: ArraySpec) -> int:
101101
return input_byte_length
102102

103103

zarr/v3/codecs/crc32c_.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ def get_metadata_class(cls) -> Type[Crc32cCodecMetadata]:
4040
async def decode(
4141
self,
4242
chunk_bytes: bytes,
43-
_chunk_metadata: ArraySpec,
43+
_chunk_spec: ArraySpec,
4444
_runtime_configuration: RuntimeConfiguration,
4545
) -> BytesLike:
4646
crc32_bytes = chunk_bytes[-4:]
@@ -52,12 +52,12 @@ async def decode(
5252
async def encode(
5353
self,
5454
chunk_bytes: bytes,
55-
_chunk_metadata: ArraySpec,
55+
_chunk_spec: ArraySpec,
5656
_runtime_configuration: RuntimeConfiguration,
5757
) -> Optional[BytesLike]:
5858
return chunk_bytes + np.uint32(crc32c(chunk_bytes)).tobytes()
5959

60-
def compute_encoded_size(self, input_byte_length: int, _chunk_metadata: ArraySpec) -> int:
60+
def compute_encoded_size(self, input_byte_length: int, _chunk_spec: ArraySpec) -> int:
6161
return input_byte_length + 4
6262

6363

zarr/v3/codecs/gzip.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,23 +47,23 @@ def get_metadata_class(cls) -> Type[GzipCodecMetadata]:
4747
async def decode(
4848
self,
4949
chunk_bytes: bytes,
50-
_chunk_metadata: ArraySpec,
50+
_chunk_spec: ArraySpec,
5151
_runtime_configuration: RuntimeConfiguration,
5252
) -> BytesLike:
5353
return await to_thread(GZip(self.configuration.level).decode, chunk_bytes)
5454

5555
async def encode(
5656
self,
5757
chunk_bytes: bytes,
58-
_chunk_metadata: ArraySpec,
58+
_chunk_spec: ArraySpec,
5959
_runtime_configuration: RuntimeConfiguration,
6060
) -> Optional[BytesLike]:
6161
return await to_thread(GZip(self.configuration.level).encode, chunk_bytes)
6262

6363
def compute_encoded_size(
6464
self,
6565
_input_byte_length: int,
66-
_chunk_metadata: ArraySpec,
66+
_chunk_spec: ArraySpec,
6767
) -> int:
6868
raise NotImplementedError
6969

0 commit comments

Comments
 (0)