Skip to content

Commit 4b26501

Browse files
TomAugspurgerd-v-b
andauthored
Optimize getitem with empty chunks (#3379)
Co-authored-by: Davis Bennett <[email protected]>
1 parent c2c4e21 commit 4b26501

File tree

4 files changed

+10
-6
lines changed

4 files changed

+10
-6
lines changed

changes/3368.misc.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Improved performance of reading arrays by not unnecessarily using
2+
the fill value.

src/zarr/abc/codec.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -427,6 +427,11 @@ async def read(
427427
The second slice selection determines where in the output array the chunk data will be written.
428428
The ByteGetter is used to fetch the necessary bytes.
429429
The chunk spec contains information about the construction of an array from the bytes.
430+
431+
If the Store returns ``None`` for a chunk, then the chunk was not
432+
written and the implementation must set the values of that chunk (or
433+
``out``) to the fill value for the array.
434+
430435
out : NDBuffer
431436
"""
432437
...

src/zarr/codecs/sharding.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -451,11 +451,10 @@ async def _decode_single(
451451
)
452452

453453
# setup output array
454-
out = chunk_spec.prototype.nd_buffer.create(
454+
out = chunk_spec.prototype.nd_buffer.empty(
455455
shape=shard_shape,
456456
dtype=shard_spec.dtype.to_native_dtype(),
457457
order=shard_spec.order,
458-
fill_value=0,
459458
)
460459
shard_dict = await _ShardReader.from_bytes(shard_bytes, self, chunks_per_shard)
461460

@@ -498,11 +497,10 @@ async def _decode_partial_single(
498497
)
499498

500499
# setup output array
501-
out = shard_spec.prototype.nd_buffer.create(
500+
out = shard_spec.prototype.nd_buffer.empty(
502501
shape=indexer.shape,
503502
dtype=shard_spec.dtype.to_native_dtype(),
504503
order=shard_spec.order,
505-
fill_value=0,
506504
)
507505

508506
indexed_chunks = list(indexer)

src/zarr/core/array.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1349,11 +1349,10 @@ async def _get_selection(
13491349
f"shape of out argument doesn't match. Expected {indexer.shape}, got {out.shape}"
13501350
)
13511351
else:
1352-
out_buffer = prototype.nd_buffer.create(
1352+
out_buffer = prototype.nd_buffer.empty(
13531353
shape=indexer.shape,
13541354
dtype=out_dtype,
13551355
order=self.order,
1356-
fill_value=self.metadata.fill_value,
13571356
)
13581357
if product(indexer.shape) > 0:
13591358
# need to use the order from the metadata for v2

0 commit comments

Comments
 (0)