Skip to content

refactor(sharding): store chunks_per_shard explicitly in _ShardIndex#3975

Open
d-v-b wants to merge 5 commits into
zarr-developers:mainfrom
d-v-b:chunk-index-tweak
Open

refactor(sharding): store chunks_per_shard explicitly in _ShardIndex#3975
d-v-b wants to merge 5 commits into
zarr-developers:mainfrom
d-v-b:chunk-index-tweak

Conversation

@d-v-b
Copy link
Copy Markdown
Contributor

@d-v-b d-v-b commented May 14, 2026

_ShardIndex previously inferred the chunk grid shape from
offsets_and_lengths.shape[:-1]. For 0-D arrays this collapses the array
to rank-1, breaking methods that assume rank >= 2 and forcing a numpy
compat cast workaround.

Store chunks_per_shard as an explicit NamedTuple field instead. This
removes the chunks_per_shard property and its cast, and lets several
call sites use the field directly instead of reverse-engineering it.

Also fix a latent 0-D bug in is_dense, which iterated offsets_and_lengths
assuming rank-2.

Closes #3974

Co-Authored-By: Claude Opus 4.7 (1M context) noreply@anthropic.com

_ShardIndex previously inferred the chunk grid shape from
offsets_and_lengths.shape[:-1]. For 0-D arrays this collapses the array
to rank-1, breaking methods that assume rank >= 2 and forcing a numpy
compat cast workaround.

Store chunks_per_shard as an explicit NamedTuple field instead. This
removes the chunks_per_shard property and its cast, and lets several
call sites use the field directly instead of reverse-engineering it.

Also fix a latent 0-D bug in is_dense, which iterated offsets_and_lengths
assuming rank-2.

Closes zarr-developers#3974

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@github-actions github-actions Bot added the needs release notes Automatically applied to PRs which haven't added release notes label May 14, 2026
@d-v-b d-v-b requested a review from ilan-gold May 14, 2026 12:32
@codecov
Copy link
Copy Markdown

codecov Bot commented May 14, 2026

Codecov Report

❌ Patch coverage is 90.90909% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 93.29%. Comparing base (e815b51) to head (152132c).

Files with missing lines Patch % Lines
src/zarr/codecs/sharding.py 90.90% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3975      +/-   ##
==========================================
- Coverage   93.29%   93.29%   -0.01%     
==========================================
  Files          87       87              
  Lines       11752    11744       -8     
==========================================
- Hits        10964    10956       -8     
  Misses        788      788              
Files with missing lines Coverage Δ
src/zarr/codecs/sharding.py 89.06% <90.90%> (-0.27%) ⬇️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

d-v-b and others added 2 commits May 14, 2026 15:46
_ShardIndex previously inferred the chunk grid shape from
offsets_and_lengths.shape[:-1]. For 0-D arrays this collapses the array
to rank-1, breaking methods that assume rank >= 2 and forcing a numpy
compat cast workaround.

Store chunks_per_shard as an explicit NamedTuple field instead. This
removes the chunks_per_shard property and its cast, and lets several
call sites use the field directly instead of reverse-engineering it.

Also fix a latent 0-D bug in is_dense, which iterated offsets_and_lengths
assuming rank-2.

Tests for get_chunk_slices_vectorized, _ShardReader.__iter__, and
is_dense are parametrized over chunk grid ranks (0-D, 1-D, 2-D) so 0-D
is exercised as a normal case rather than a special branch.

Closes zarr-developers#3974

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs release notes Automatically applied to PRs which haven't added release notes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

explicitly encode chunk grid shape in _ShardIndex

1 participant