Skip to content

Enable reading scalar attributes stored as shape-(1,) arrays. - #81

Merged
krischer merged 2 commits into
SeismicData:mainfrom
boehmc:scalar-attributes-as-arrays
Aug 5, 2026
Merged

krischer merged 2 commits into
SeismicData:mainfrom
boehmc:scalar-attributes-as-arrays

Conversation

@boehmc

@boehmc boehmc commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

This was probably never intended as PyASDF's own writer would use a scalar attribute in the first place. However, external writers might use H5LTset_attribute_*(..., size=1) which creates a size-1 array instead of an H5S_SCALAR.

This PR converts attributes stored as size-1 arrays to scalar attributes. Without squeezing the arrays to scalars, numpy >=2.4.0 raises a type error like this:

TypeError: only 0-dimensional arrays can be converted to Python scalars.

boehmc added 2 commits August 3, 2026 22:09
This was probably never intended as PyASDF's own writer would use
a scalar attribute in the first place. However, external writers
might use H5LTset_attribute_*(..., size=1) which creates a size-1
array instead of an H5S_SCALAR.

This still works fine with numpy <2.4.0, but from 2.4.0 onwards,
it raises a type error rather than silently squeezing to a float:

TypeError: only 0-dimensional arrays can be converted to Python
scalars.
@krischer
krischer merged commit 4eca3c6 into SeismicData:main Aug 5, 2026
13 checks passed
@krischer

krischer commented Aug 5, 2026

Copy link
Copy Markdown
Member

Thank you!

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