Repository navigation
Commit d3dc9f5
authored
fix: accept numpy integers as chunk sizes (zarr-developers#4257)
* fix: accept numpy integers as chunk sizes
`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
* Rename 4255.bugfix.md to 4257.bugfix.md1 parent 6ba6e89 commit d3dc9f5
4 files changed
Lines changed: 44 additions & 10 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
729 | 729 | | |
730 | 730 | | |
731 | 731 | | |
732 | | - | |
733 | | - | |
734 | | - | |
735 | | - | |
736 | | - | |
| 732 | + | |
| 733 | + | |
| 734 | + | |
| 735 | + | |
| 736 | + | |
| 737 | + | |
| 738 | + | |
| 739 | + | |
737 | 740 | | |
738 | | - | |
739 | | - | |
740 | | - | |
| 741 | + | |
| 742 | + | |
| 743 | + | |
741 | 744 | | |
742 | | - | |
| 745 | + | |
| 746 | + | |
| 747 | + | |
| 748 | + | |
| 749 | + | |
| 750 | + | |
| 751 | + | |
743 | 752 | | |
744 | 753 | | |
745 | 754 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
79 | 79 | | |
80 | 80 | | |
81 | 81 | | |
82 | | - | |
| 82 | + | |
83 | 83 | | |
84 | 84 | | |
85 | 85 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
68 | 68 | | |
69 | 69 | | |
70 | 70 | | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
71 | 80 | | |
72 | 81 | | |
73 | 82 | | |
| |||
142 | 151 | | |
143 | 152 | | |
144 | 153 | | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
145 | 160 | | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
146 | 170 | | |
147 | 171 | | |
148 | 172 | | |
| |||
0 commit comments