fix(rl): robust integer validation for utils.py (Fixes #953) #1000
+53
−4
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.
This PR fixes an AttributeError crash encountered when using is_positive_integer with Numpy types (e.g., np.int64) or on Python 3.11+ where certain types lack the .is_integer() method.
This supersedes stale PRs #903 and #930. I have consolidated the fix and added the missing unit tests requested by maintainers.
Changes:
Implemented a safe is_integer_value helper that handles int, float, and numpy types correctly.
Added tests/rl/rl_utils_test.py to verify the fix across all types.
Related Issues:
Fixes #953
Resolves #903
Resolves #902
Test Plan
Created a new test file tests/rl/rl_utils_test.py. Verified locally with python3 -m unittest tests/rl/rl_utils_test.py.
Results:
✅ int (Standard) - Passed
✅ np.int64 (Numpy) - Passed (Previously crashed)
✅ float (Standard) - Passed
✅ bool - Rejected correctly