Skip to content

Fix numpy >= 2.0 TypeError in polyfit#150

Open
scottstanie wants to merge 1 commit intoisce-framework:mainfrom
scottstanie:fix/numpy2-polyfit-scalar
Open

Fix numpy >= 2.0 TypeError in polyfit#150
scottstanie wants to merge 1 commit intoisce-framework:mainfrom
scottstanie:fix/numpy2-polyfit-scalar

Conversation

@scottstanie
Copy link
Member

@scottstanie scottstanie commented Feb 26, 2026

Summary

  • Fix TypeError: only 0-dimensional arrays can be converted to Python scalars when using s1reader with numpy >= 2.0
  • np.linalg.lstsq returns res as a 1-element array. In numpy >= 2.0, %f string formatting no longer implicitly converts arrays to scalars. Added .item() to explicitly extract the scalar value.

See also Piyush's PR on isce3: isce-framework/isce3#226

Test plan

  • Verified fix with numpy 2.4.1 - polyfit now prints chi-squared correctly instead of raising TypeError
  • Pre-commit hooks pass

`np.linalg.lstsq` returns `res` as a 1-element array. In numpy >= 2.0,
`%f` string formatting no longer implicitly converts arrays to scalars,
raising `TypeError: only 0-dimensional arrays can be converted to Python
scalars`. Use `.item()` to explicitly extract the scalar value.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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.

1 participant