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.
Adhering to NEP 50,
np.can_cast
no longer applies any value-based logic for 0-D arrays and NumPy scalars.Using
np.min_scalar_type(value)
, the data type with the smallest size and smallest scalar kind that can holdvalue
is checked againstdtype
.However, there is still another issue due to the below schema of numpy 2.0.0's promotion rules:
For example, in the case of casting
np.int64(5)
tonp.int8
,np.min_scalar_type(np.int64(5))
returnsnp.uint8
, and according to the diagram,np.uint8
can not be casted tonp.int8
. I have manually checked ifvalue
is of kinduint
and dtype is of kindnp.signedinteger
and if the casting can safely happen.