Skip to content

Replace removed np.float_ alias with np.float64 for NumPy 2.0 compatibility - #583

Open
teddytennant wants to merge 2 commits into
Farama-Foundation:mainfrom
teddytennant:fix-np-float-alias
Open

teddytennant wants to merge 2 commits into
Farama-Foundation:mainfrom
teddytennant:fix-np-float-alias

Conversation

@teddytennant

Copy link
Copy Markdown

What

rect_prism_tolerance in metaworld/utils/reward_utils.py annotated its three parameters as npt.NDArray[np.float_]. This replaces those three annotations with npt.NDArray[np.float64] and adds a small test file tests/metaworld/test_reward_utils.py.

Why

np.float_ was removed in NumPy 2.0 — it was only ever an alias for np.float64. Metaworld declares requires-python = ">=3.10,<3.14" and lists Python 3.13 in its classifiers/CI matrix, and Python 3.13 cannot use NumPy 1.x, so the NumPy 2 code path is a supported, exercised configuration.

Because reward_utils.py uses from __future__ import annotations, the annotations are stored as strings and this does not crash at import time. However, any consumer that resolves the annotations under NumPy >= 2 hits:

AttributeError: module 'numpy' has no attribute 'float_'

This includes typing.get_type_hints(rect_prism_tolerance) and mypy runs against the package (Metaworld ships a py.typed marker, so its annotations are part of the public typed API). The pre-commit mypy hook is pinned to numpy==1.26.1, where np.float_ still exists, which is why this went unnoticed.

np.float64 is valid and identical in meaning on both NumPy 1.x and 2.x, so the change is fully backward compatible and still passes the numpy==1.26.1-pinned pre-commit mypy.

rect_prism_tolerance is live code: it is called twice in metaworld/envs/sawyer_peg_insertion_side_v3.py for the collision-box reward term.

Testing

Added tests/metaworld/test_reward_utils.py with two tests:

  • test_rect_prism_tolerance_type_hints_resolvable — resolves the function's type hints via typing.get_type_hints. This fails before the fix (AttributeError: np.float_ was removed in the NumPy 2.0 release) and passes after, under numpy >= 2.
  • test_rect_prism_tolerance_values — documents the reward values at the two prism corners and outside the prism.

Run:

python -m pytest tests/metaworld/test_reward_utils.py -q

Verified with numpy 2.5.1 on Python 3.13: 2 passed. black/isort clean on the changed files.

`np.float_` was removed in NumPy 2.0 (it was only ever an alias for
`np.float64`). `rect_prism_tolerance` annotates its three parameters with
`npt.NDArray[np.float_]`; because the module uses
`from __future__ import annotations` this does not fail at import time, but
resolving the annotations under NumPy>=2 (mandatory on Python 3.13, which is
in the supported/CI matrix) raises `AttributeError: module 'numpy' has no
attribute 'float_'`. This affects `typing.get_type_hints` and mypy consumers,
since the package ships a `py.typed` marker.

`np.float64` is valid and identical in meaning on both NumPy 1.x and 2.x.

Add tests/metaworld/test_reward_utils.py covering annotation resolution and
the function's reward values.
Copilot AI review requested due to automatic review settings July 8, 2026 20:25

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

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.

3 participants