fix: handle numpy scalar types in safe_json_value#35389
Open
avasis-ai wants to merge 1 commit intolanggenius:mainfrom
Open
fix: handle numpy scalar types in safe_json_value#35389avasis-ai wants to merge 1 commit intolanggenius:mainfrom
avasis-ai wants to merge 1 commit intolanggenius:mainfrom
Conversation
fatelei
approved these changes
Apr 19, 2026
Contributor
|
-- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html Coverage XML written to file coverage.xml |
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.
Summary
Add explicit handling for
np.integerandnp.floatingscalar types insafe_json_value().Problem
safe_json_value()handlesnp.ndarray(via.tolist()) but misses numpy scalar types likenp.int64,np.float64, etc. These fall through to theelseclause and are returned as-is. Sincejson.dumps()cannot serialize numpy scalar types, this causes aTypeErrorat runtime when tool results contain numpy scalars.In numpy >= 2.0, scalar types no longer inherit from Python builtins, making this even more likely to fail.
Change
Added two checks before the existing
np.ndarrayhandling:np.integer→int(v)np.floating→float(v)Related to #34405 (parameter precision loss with numeric types).