BUG: Make sure that NumPy scalars are supported by can_cast#26393
Merged
charris merged 2 commits intonumpy:maintenance/2.0.xfrom May 7, 2024
Merged
BUG: Make sure that NumPy scalars are supported by can_cast#26393charris merged 2 commits intonumpy:maintenance/2.0.xfrom
charris merged 2 commits intonumpy:maintenance/2.0.xfrom
Conversation
The main issue here was the order of the checks, since float64 is a subclass of float the error path was taken even though it should not have been. This also avoids converting to an array (which is very slow) when possible. I opted to use `scalar.dtype` since that may be a bit easier for potential future user dtype. That may not be quite ideal (I would like to not force `np.generic` as a base-class for user scalars), but is probably pretty close and more complicated fixes are probably not good for backport.
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.
Backport of #26372.
The main issue here was the order of the checks, since float64 is
a subclass of float the error path was taken even though it should
not have been.
This also avoids converting to an array (which is very slow) when
possible. I opted to use
scalar.dtypesince that may be a biteasier for potential future user dtype.
That may not be quite ideal (I would like to not force
np.genericas a base-class for user scalars), but is probably pretty close
and more complicated fixes are probably not good for backport.
Closes gh-26370
Also adds a
can_castchange to the relase notes as it was missing.