Fix packing of 0-dim arrays - #683
Merged
Merged
Conversation
The empty-data guard added in e5f5275 used len(data), which NumPy refuses on 0-dim arrays, so pack_array2/pack_tensor raised "TypeError: len() of unsized object" for them since 3.0. Test the buffer length instead, and fold the check into the nchunks computation, where it is needed to avoid dividing by a chunksize of 0 for empty arrays. Fixes Blosc#680.
Contributor
There was a problem hiding this comment.
Pull request overview
This pull request fixes a regression where packing/unpacking 0‑dim (scalar) NumPy arrays fails (e.g., TypeError: len() of unsized object), restoring correct behavior for pack_tensor / pack_array2 round-trips.
Changes:
- Update
SChunkinitialization to rely on buffer length (Py_buffer.len) rather thanlen(data)-based gating, enabling 0‑D NumPy arrays to be packed. - Add a pytest case covering 0‑D scalar tensors for both
pack_tensorand thepack_array2/unpack_array2wrappers.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
src/blosc2/blosc2_ext.pyx |
Removes len(data)-based check and computes chunk count from the buffer length so 0‑D NumPy arrays can be packed correctly. |
tests/test_tensor.py |
Adds regression tests ensuring scalar (0‑D) arrays round-trip via pack_tensor/unpack_tensor and pack_array2/unpack_array2. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Member
|
Thanks @Zentrik ! |
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.
Fixes #680.
I did use claude for this, but the change seems basically what I would have written by hand.