Skip to content

fix: NumPy 2.0 compatibility for scalar metadata / fission-yield conversion - #540

Closed
steps-re wants to merge 1 commit into
CORE-GATECH-GROUP:mainfrom
steps-re:fix/numpy2-scalar-conversion
Closed

steps-re wants to merge 1 commit into
CORE-GATECH-GROUP:mainfrom
steps-re:fix/numpy2-scalar-conversion

Conversation

@steps-re

Copy link
Copy Markdown
Contributor

Problem

CI is red on current runners across all supported Python versions. The bulk of the failures (≈53 of 58 per job) are a single root cause:

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

The last green main run predates the NumPy 2.0 rollout on ubuntu-latest; any run today hits this. It reproduces on a clean main checkout with NumPy 2.5.1 / Python 3.13, so it is independent of any feature branch — it blocks every open PR's CI.

Root cause

NumPy 2.0 removed implicit conversion of non 0-d arrays to Python scalars. Serpent scalar metadata (and single fission-yield lookups) are parsed into size-1 arrays, so int(...) / float(...) on them now raises. Affected sites:

  • ResultsReader._cleanMetadata — hit by nearly every test that reads a _res.m file
  • MicroXSReader fission-yield parsing (parent id, energy, and the getFY lookup)

Fix

Unwrap size-1 arrays with .item() before converting. Behavior is unchanged on older NumPy, where int()/float() on a size-1 array already returned the scalar.

Testing

Full suite on main + this fix (Python 3.13, NumPy 2.5.1, with scipy/pandas installed):

  • Before: 36 failed, 29 errors
  • After: 346 passed, zero scalar-conversion errors

Not covered here

A handful of matplotlib image-comparison tests still fail on current runners due to baseline-PNG drift against newer matplotlib. That is a separate, pre-existing issue (unrelated to NumPy) and is intentionally left out of this PR — filed separately for maintainer triage.

…nversion

NumPy 2.0 removed implicit conversion of non 0-d arrays to Python
scalars, so int()/float() on a size-1 array now raises
"TypeError: only 0-dimensional arrays can be converted to Python scalars".

Serpent scalar metadata (and single fission-yield lookups) are parsed
into size-1 arrays, so ResultsReader._cleanMetadata and several
MicroXSReader conversions broke under NumPy >= 2.0. This fails the
majority of the test suite on current runners.

Unwrap size-1 arrays via .item() before converting. Behavior is
unchanged on older NumPy (int()/float() on a size-1 array already
returned the scalar there).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@drewejohnson

Copy link
Copy Markdown
Collaborator

This should be handled in #543

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