Skip to content

Fix asarray when chunk dims are greater than shape dims - #698

Merged
FrancescAlted merged 3 commits into
Blosc:mainfrom
Zentrik:fix-asarray-overhanging-chunks
Aug 11, 2026
Merged

FrancescAlted merged 3 commits into
Blosc:mainfrom
Zentrik:fix-asarray-overhanging-chunks

Conversation

@Zentrik

@Zentrik Zentrik commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

asarray() leaves arrays over 16 MB unreadable when the chunk shape is greater than the shape:

a = np.arange(146 * 23802, dtype=np.float64).reshape(146, 23802)
b = blosc2.asarray(a, chunks=(147, 23802), blocks=(1, 23802))
b[:]  # RuntimeError: Error while getting the buffer

This seems to be because asarray has a separate path for large arrays which calls schunk.update_data() on its fastpath if are_partitions_behaved. I have changed are_partitions_behaved to no longer return true for this example and tried to simplify the existing logic which I found hard to follow. I've tried to preserve the old behaviour whilst also checking that size % unit == 0 if size < unit.

The other uses of are_partitions_behaved seem to live in lazyexpr.py and are of the form behaved and result.shape == out.chunks and result.dtype == out.dtype so I think they're unaffected.

Zentrik added 3 commits August 7, 2026 12:55
Above 16 MB, asarray fills chunk by chunk through SChunk.update_data(),
guarded by are_partitions_behaved(). That guard only rejected partitions
smaller than their container, so chunks sticking out of the shape (e.g.
shape (146, 23802), chunks (147, 23802)) passed, and update_data() got a
slice one row short of the padded chunkshape; reading the array back
failed with "Error while getting the buffer".

Rejecting overhanging partitions collapses check_contiguity() to its two
real conditions: unsplit innermost dimension, outer dimensions divided
evenly.
@Zentrik Zentrik changed the title Fix asarray overhanging chunks Fix asarray when chunk dims are greater than shape dims Aug 11, 2026
@FrancescAlted

Copy link
Copy Markdown
Member

Well seen, and the fix looks good to me. Merging. Thanks @Zentrik !

@FrancescAlted
FrancescAlted merged commit 5cc0c03 into Blosc:main Aug 11, 2026
14 of 15 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.

2 participants