Skip to content

BUG: Make sure that NumPy scalars are supported by can_cast#26393

Merged
charris merged 2 commits intonumpy:maintenance/2.0.xfrom
charris:backport-26372
May 7, 2024
Merged

BUG: Make sure that NumPy scalars are supported by can_cast#26393
charris merged 2 commits intonumpy:maintenance/2.0.xfrom
charris:backport-26372

Conversation

@charris
Copy link
Member

@charris charris commented May 6, 2024

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.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.

Closes gh-26370


Also adds a can_cast change to the relase notes as it was missing.

seberg added 2 commits May 6, 2024 16:53
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.
@charris charris added 00 - Bug 08 - Backport Used to tag backport PRs labels May 6, 2024
@charris charris added this to the 2.0.0 release milestone May 6, 2024
@charris charris merged commit d384db6 into numpy:maintenance/2.0.x May 7, 2024
@charris charris deleted the backport-26372 branch May 7, 2024 02:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

00 - Bug 08 - Backport Used to tag backport PRs

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants