Skip to content

Commit 501e7a5

Browse files
committed
Self review
1 parent c7ddb0e commit 501e7a5

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

src/zarr/codecs/sharding.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -778,7 +778,7 @@ async def _load_partial_shard_maybe(
778778
) -> ShardMapping | None:
779779
"""
780780
Read chunks from `byte_getter` for the case where the read is less than a full shard.
781-
Returns a mapping of chunk coordinates to bytes.
781+
Returns a mapping of chunk coordinates to bytes or None.
782782
"""
783783
shard_index = await self._load_shard_index_maybe(byte_getter, chunks_per_shard)
784784
if shard_index is None:
@@ -788,11 +788,9 @@ async def _load_partial_shard_maybe(
788788
_ChunkCoordsByteSlice(chunk_coords, slice(*chunk_byte_slice))
789789
for chunk_coords in all_chunk_coords
790790
# Drop chunks where index lookup fails
791-
# e.g. when write_empty_chunks = False and the chunk is empty
791+
# e.g. empty chunks when write_empty_chunks = False
792792
if (chunk_byte_slice := shard_index.get_chunk_slice(chunk_coords))
793793
]
794-
if len(chunks) == 0:
795-
return None
796794

797795
groups = self._coalesce_chunks(chunks)
798796

@@ -816,7 +814,7 @@ def _coalesce_chunks(
816814
) -> list[list[_ChunkCoordsByteSlice]]:
817815
"""
818816
Combine chunks from a single shard into groups that should be read together
819-
in a single request.
817+
in a single request to the store.
820818
821819
Respects the following configuration options:
822820
- `sharding.read.coalesce_max_gap_bytes`: The maximum gap between
@@ -828,6 +826,9 @@ def _coalesce_chunks(
828826

829827
sorted_chunks = sorted(chunks, key=lambda c: c.byte_slice.start)
830828

829+
if len(sorted_chunks) == 0:
830+
return []
831+
831832
groups = []
832833
current_group = [sorted_chunks[0]]
833834

tests/test_codecs/test_sharding.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,7 @@ def test_sharding_read_empty_chunks_within_non_empty_shard_write_empty_false(
354354
- some, but not all, chunks in the last shard are empty
355355
- the last shard is not complete (array length is not a multiple of shard shape),
356356
this takes us down the partial shard read path
357-
- write_empty_chunks=False so the shard index will have less entries than chunks in the shard
357+
- write_empty_chunks=False so the shard index will have fewer entries than chunks in the shard
358358
"""
359359
# array with mixed empty and non-empty chunks in second shard
360360
data = np.array([

0 commit comments

Comments
 (0)