Replace removed np.float_ alias with np.float64 for NumPy 2.0 compatibility - #583
Open
teddytennant wants to merge 2 commits into
Open
teddytennant wants to merge 2 commits into
teddytennant wants to merge 2 commits into
Conversation
`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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
rect_prism_toleranceinmetaworld/utils/reward_utils.pyannotated its three parameters asnpt.NDArray[np.float_]. This replaces those three annotations withnpt.NDArray[np.float64]and adds a small test filetests/metaworld/test_reward_utils.py.Why
np.float_was removed in NumPy 2.0 — it was only ever an alias fornp.float64. Metaworld declaresrequires-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.pyusesfrom __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:This includes
typing.get_type_hints(rect_prism_tolerance)andmypyruns against the package (Metaworld ships apy.typedmarker, so its annotations are part of the public typed API). The pre-commit mypy hook is pinned tonumpy==1.26.1, wherenp.float_still exists, which is why this went unnoticed.np.float64is 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_toleranceis live code: it is called twice inmetaworld/envs/sawyer_peg_insertion_side_v3.pyfor the collision-box reward term.Testing
Added
tests/metaworld/test_reward_utils.pywith two tests:test_rect_prism_tolerance_type_hints_resolvable— resolves the function's type hints viatyping.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:
Verified with numpy 2.5.1 on Python 3.13:
2 passed.black/isortclean on the changed files.