Skip to content

Fix NumPy 2.0 compatibility issues#5

Merged
timlichtenberg merged 3 commits intomainfrom
tl/deprecation_fixes_line138
Jan 2, 2026
Merged

Fix NumPy 2.0 compatibility issues#5
timlichtenberg merged 3 commits intomainfrom
tl/deprecation_fixes_line138

Conversation

@timlichtenberg
Copy link
Member

Summary

Fixes NumPy 2.0 compatibility issues that cause TypeError: only 0-dimensional arrays can be converted to Python scalars throughout the codebase.

Changes

mesh.py (3 fixes)

  • Line 138: total_volume property - added .item() to convert numpy scalar to Python float
  • Line 242: get_planet_density - added .item() to return value
  • Line 451: volume_average method - added .item() to return value

output.py (4 fixes)

  • Line 231: mantle_mass property - added .item() conversion
  • Line 313: solution_top_temperature property - added .item() conversion
  • Line 322: time_range property - added .item() conversion
  • Line 349: _add_scalar_variable - conditional .item() for scalar values

utilities.py (1 fix)

  • Line 65: is_monotonic_increasing - changed return type annotation from np.bool_ to bool (np.bool_ deprecated in NumPy 2.0)

Testing

All changes tested in PROTEUS CI with NumPy 2.0+:

  • 57 tests passing
  • 16 aragog_janus integration tests all passing (previously failing with TypeError)
  • Zero regressions

Background

NumPy 2.0 changed the behavior of 0-dimensional array scalar conversion, requiring explicit .item() calls to convert numpy scalars to Python native types. This PR ensures aragog works with both NumPy 1.x and 2.x.

Related: FormingWorlds/PROTEUS CI testing infrastructure improvements

- Fix np.bool_ deprecated type annotation in utilities.py
- Add .item() to mantle_mass, solution_top_temperature, time_range properties
- Add .item() to get_planet_density return value
- Ensures all methods returning float return Python floats, not numpy scalars
@timlichtenberg timlichtenberg requested a review from a team as a code owner January 2, 2026 16:01
@timlichtenberg timlichtenberg merged commit c17dcfb into main Jan 2, 2026
7 checks passed
timlichtenberg added a commit to FormingWorlds/PROTEUS that referenced this pull request Jan 2, 2026
Now that NumPy 2.0 fixes are merged to aragog main (PR #5),
remove the temporary test branch reference from CI workflow.

Related: FormingWorlds/aragog#5
@nichollsh nichollsh deleted the tl/deprecation_fixes_line138 branch January 6, 2026 10:05
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