Skip to content

Commit 3df3ca0

Browse files
committed
Code clarity and comments
1 parent e965431 commit 3df3ca0

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

src/zarr/codecs/sharding.py

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -570,6 +570,15 @@ def _coalesce_chunks(
570570
self,
571571
chunks: list[_ChunkCoordsByteSlice],
572572
) -> list[list[_ChunkCoordsByteSlice]]:
573+
"""
574+
Combine chunks from a single shard into groups that should be read together
575+
in a single request.
576+
577+
Respects the following configuration options:
578+
- `sharding.read.coalesce_max_gap_bytes`: The maximum gap between
579+
chunks to coalesce into a single group.
580+
- `sharding.read.coalesce_max_bytes`: The maximum number of bytes in a group.
581+
"""
573582
max_gap_bytes = config.get("sharding.read.coalesce_max_gap_bytes")
574583
coalesce_max_bytes = config.get("sharding.read.coalesce_max_bytes")
575584

@@ -602,17 +611,23 @@ async def _get_group_bytes(
602611
group_start = group[0].byte_slice.start
603612
group_end = group[-1].byte_slice.stop
604613

614+
# A single call to retrieve the bytes for the entire group.
605615
group_bytes = await byte_getter.get(
606616
prototype=prototype,
607617
byte_range=RangeByteRequest(group_start, group_end),
608618
)
609619
if group_bytes is None:
610620
return {}
611621

622+
# Extract the bytes corresponding to each chunk in group from group_bytes.
612623
shard_dict = {}
613624
for chunk in group:
614-
s = slice(chunk.byte_slice.start - group_start, chunk.byte_slice.stop - group_start)
615-
shard_dict[chunk.coords] = group_bytes[s]
625+
chunk_slice = slice(
626+
chunk.byte_slice.start - group_start,
627+
chunk.byte_slice.stop - group_start,
628+
)
629+
shard_dict[chunk.coords] = group_bytes[chunk_slice]
630+
616631
return shard_dict
617632

618633
async def _encode_single(

0 commit comments

Comments
 (0)