Conversation
`_set_selection` passed the value to the codec pipeline unchecked, and the pipeline slices it with each chunk's `out_selection`. A value longer than the selection was silently truncated (`zeros((3,))[...] = arange(4)`), and values numpy would broadcast (a length-1 axis, a lower-rank value, leading length-1 axes) raised or wrote partial data depending on chunk layout. The value is now broadcast to the selection shape under numpy's assignment rules before any chunk is touched, raising numpy's "could not broadcast" `ValueError` otherwise. Coordinate and mask selections broadcast to `sel_shape` and are then flattened, which replaces the ad-hoc flatten and element-count check in `Array.set_coordinate_selection`. Assisted-by: ClaudeCode:claude-opus-5-5
Assisted-by: ClaudeCode:claude-opus-5-5
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #4456 +/- ##
==========================================
- Coverage 94.46% 94.44% -0.02%
==========================================
Files 93 93
Lines 13234 13238 +4
==========================================
+ Hits 12501 12503 +2
- Misses 733 735 +2
🚀 New features to boost your workflow:
|
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
🤖 AI text below 🤖
Writing a value whose shape does not broadcast to the selection now raises
ValueError, as numpy does, instead of silently writing a truncated value; this also coverszarr.create(shape, data=...). Values that numpy broadcasts, such as a length-1 axis, a lower-rank value, or extra leading length-1 axes, are now written correctly for every selection type instead of raising or writing partial data.Summary
_set_selectionpassed the value to the codec pipeline unchecked, and the pipeline slices it with each chunk'sout_selection. So a value longer than the selection was truncated, and values numpy accepts failed or wrote partial data depending on chunk layout, for example a(1,)value spanning several chunks,(3,)into(4, 3), a leading length-1 axis, or a(1,)value viavindex.The value is now broadcast to the selection shape under numpy's assignment rules (
_broadcast_to_selection) before any chunk is touched, raising numpy'scould not broadcast input array from shape X into shape Yotherwise. 0-d values pass through unchanged so the pipeline's scalar fast paths still apply. Coordinate and mask selections broadcast tosel_shapeand are then flattened, which replaces the ad-hoc flatten and element-count check inArray.set_coordinate_selection.For reviewers
test_set_selection_rejects_value_with_wrong_rankwas updated, and its docstring no longer describes an oindex write that chunked arrays accepted and sharded arrays rejected, since both now reject it.Tests: one test covering the valid broadcasts against numpy (basic, integer axis, oindex, vindex, mask; chunked and sharded), one per error case (axis length mismatch; extra non-length-1 leading axis), plus the
zarr.create(data=...)path. 37 of the 41 new cases fail on main; the 4 that pass are exact-shape controls.Author attestation
TODO
docs/user-guide/*.mdchanges/🤖 Generated with Claude Code