Skip to content

fix: Handle inhomogeneous array shapes in to_arrays()#1382

Merged
dimitri-yatsenko merged 2 commits intomaint/2.0from
fix/inhomogeneous-arrays-1380
Feb 5, 2026
Merged

fix: Handle inhomogeneous array shapes in to_arrays()#1382
dimitri-yatsenko merged 2 commits intomaint/2.0from
fix/inhomogeneous-arrays-1380

Conversation

@dimitri-yatsenko
Copy link
Member

Summary

  • Fix to_arrays() failing when arrays have different but "almost compatible" shapes (e.g., (100,) vs (100, 1))
  • Create empty object array and assign elements individually to avoid numpy broadcasting issues

Problem

When fetching blob attributes containing arrays of different shapes, to_arrays() would fail:

# Arrays with shapes (100,), (100, 1), (100, 2)
RandomNumbers.to_arrays('values1')  # ValueError

The fallback np.array(values, dtype=object) still fails because numpy tries to broadcast shapes that are "almost compatible".

Solution

Instead of np.array(values, dtype=object), create an empty object array and assign elements individually:

arr = np.empty(len(values), dtype=object)
for i, v in enumerate(values):
    arr[i] = v

This matches v0.14.7 behavior where fetch(*attrs) extracted columns from structured arrays with dtype=object, preserving individual array shapes.

Test plan

  • Verified fix handles the reported case
  • Add test case for inhomogeneous array shapes

Fixes #1380

🤖 Generated with Claude Code

dimitri-yatsenko and others added 2 commits February 5, 2026 10:06
When arrays have different shapes, np.array(values, dtype=object) can
still fail due to numpy's broadcasting behavior. Instead, create an
empty object array and assign elements individually.

This matches v0.14.7 behavior where blobs were extracted from structured
arrays with object dtype columns.

Fixes #1380

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Regression tests for #1380 - verify that arrays of different shapes
are handled correctly without ValueError.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@dimitri-yatsenko dimitri-yatsenko merged commit bf6234e into maint/2.0 Feb 5, 2026
7 checks passed
@dimitri-yatsenko dimitri-yatsenko deleted the fix/inhomogeneous-arrays-1380 branch February 5, 2026 16:38
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