Skip to content

fix: accept numpy integers as chunk sizes - #4257

Merged
d-v-b merged 3 commits into
zarr-developers:mainfrom
d-v-b:claude/zarr-python-4255-8cc4db
Aug 12, 2026
Merged

fix: accept numpy integers as chunk sizes#4257
d-v-b merged 3 commits into
zarr-developers:mainfrom
d-v-b:claude/zarr-python-4255-8cc4db

Conversation

@d-v-b

@d-v-b d-v-b commented Aug 12, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes #4255 by handling numpy ints correctly in chunk input normalization. written by claude. see the original PR here: d-v-b#288

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)

d-v-b added 3 commits August 12, 2026 21:34
`normalize_chunks_nd` dispatches the scalar convenience form on
`numbers.Integral`, but `normalize_chunks_1d` narrowed on `int`. Numpy
integer scalars satisfy the former and not the latter, so a per-dimension
numpy integer passed the outer dispatch and then fell into the branch
meant for explicit per-dimension chunk sequences, where `list(chunks)`
raised `TypeError: 'numpy.int64' object is not iterable`.

Numpy integers arise naturally whenever a chunk shape is computed rather
than written as a literal, since numpy reductions and elementwise ops
yield numpy scalars.

Narrow on `numbers.Integral` and coerce with `int()`, matching the
caller and the sequence branch, which already accepted `Integral`
elements.

Move the `-1` sentinel check inside that branch. It previously ran on the
raw input, so a numpy array chunk specification made `chunks == -1`
return an array and raise an ambiguous-truth-value error; rectilinear
specs given as numpy arrays now work.

A chunk specification that is neither an integer nor iterable now names
the offending value and its type instead of surfacing an opaque
"object is not iterable" from `list(chunks)`.

Fixes zarr-developers#4255

Assisted-by: ClaudeCode:claude-opus-5
@d-v-b
d-v-b marked this pull request as ready for review August 12, 2026 19:41
@codecov

codecov Bot commented Aug 12, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 94.00%. Comparing base (6ba6e89) to head (09b06d7).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #4257   +/-   ##
=======================================
  Coverage   94.00%   94.00%           
=======================================
  Files          91       91           
  Lines       12791    12795    +4     
=======================================
+ Hits        12024    12028    +4     
  Misses        767      767           
Files with missing lines Coverage Δ
src/zarr/core/chunk_grids.py 96.97% <100.00%> (+0.03%) ⬆️
🚀 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 commented Aug 12, 2026

Copy link
Copy Markdown
Contributor Author

this is an internal bugfix so I'm going to self-merge.

@d-v-b
d-v-b merged commit d3dc9f5 into zarr-developers:main Aug 12, 2026
39 of 40 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.

Regression in 3.3.0: numpy integer chunk sizes raise TypeError: 'numpy.int64' object is not iterable

1 participant