Skip to content

fix: resolve chunks=-1 to chunk size 1 on zero-length axes - #4307

Merged
d-v-b merged 2 commits into
zarr-developers:mainfrom
d-v-b:fix/shard-guess-zero-size-chunks
Sep 2, 2026
Merged

fix: resolve chunks=-1 to chunk size 1 on zero-length axes#4307
d-v-b merged 2 commits into
zarr-developers:mainfrom
d-v-b:fix/shard-guess-zero-size-chunks

Conversation

@d-v-b

@d-v-b d-v-b commented Sep 2, 2026

Copy link
Copy Markdown
Contributor

Summary

follow up for #4304, ensures that we handle 0-length axes correctly in auto chunk size logic. written by claude, claude's PR is here

Author attestation

  • I am a human, these are my changes, and I have reviewed and understood every change and can explain why each is correct.

TODO

  • Add unit tests and/or doctests in docstrings
  • Add docstrings and API docs for any new/modified user-facing classes and functions
  • New/modified features documented in docs/user-guide/*.md
  • Changes documented as a new file in changes/
  • GitHub Actions have all passed
  • Test coverage is 100% (Codecov passes)

The -1 chunk sentinel resolved to chunk size 0 on zero-length axes,
which broke every downstream sharding path differently: a ValueError
with shards=None, a ZeroDivisionError with shards="auto", and an
infinite loop with shards="auto" plus array.target_shard_size_bytes.
Clamp it to 1, matching the auto-chunking clamp in
_guess_regular_chunks.

Also guard _guess_num_chunks_per_axis_shard against zero-size chunk
shapes directly (same non-terminating-loop cause as the 0-d case fixed
in zarr-developers#4305), and fix the arithmetic in its docstring example.

Follow-up to zarr-developers#4305 / issue zarr-developers#4304.

Assisted-by: ClaudeCode:claude-fable-5-1
Assisted-by: ClaudeCode:claude-fable-5-1
@d-v-b
d-v-b force-pushed the fix/shard-guess-zero-size-chunks branch from 873e1df to f850df5 Compare September 2, 2026 12:01
@codecov

codecov Bot commented Sep 2, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 94.21%. Comparing base (5e00e8c) to head (f850df5).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #4307   +/-   ##
=======================================
  Coverage   94.21%   94.21%           
=======================================
  Files          92       92           
  Lines       12863    12863           
=======================================
  Hits        12119    12119           
  Misses        744      744           
Files with missing lines Coverage Δ
src/zarr/core/chunk_grids.py 96.99% <100.00%> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@d-v-b d-v-b changed the title fix: resolve chunks=-1 to chunk size 1 on zero-length axes - #315 fix: resolve chunks=-1 to chunk size 1 on zero-length axes Sep 2, 2026
@d-v-b
d-v-b marked this pull request as ready for review September 2, 2026 13:25
@d-v-b

d-v-b commented Sep 2, 2026

Copy link
Copy Markdown
Contributor Author

I'm self-merging, because this is a bugfix that doesn't affect public API.

@d-v-b
d-v-b merged commit 3ec687e into zarr-developers:main Sep 2, 2026
39 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant