-
-
Notifications
You must be signed in to change notification settings - Fork 9.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ENH, MAINT: Fix behavior of int and bool in np.spacing #13931
base: main
Are you sure you want to change the base?
Conversation
d55f809
to
558821c
Compare
For ease of reviewing, can you show what the output was? |
Sure. Below is what the output was
|
Sounds like our option is to either accept this patch, or update the docs to say that How does the behavior of |
For |
You're seeing the same behavior for both functions.
This is perhaps not the best design, but it is consistent with how casting works in numpy (cc @seberg), eg for functions like It's worth noting that C++ takes a different approach here, producing an error if a cast is ambiguous. If we could redo casting without breaking everyone downstream, following the overload design of C++ might be the way to go. An aside - never use |
Needs release note. |
@eric-wieser yeah, I agree. The default TypeResolver uses the first loop which can cast all inputs safely. That kind of works, but really is more trouble than worth it it seems to me. For when we redo this, I think most of these fallbacks should be deprecated, it is OK if the ufunc has to resolve specifically Seems a bit orthogonal to this issue. For this specific thing, we have to decide if we want to rather go with a Deprecation rather than defining a spacing. Does anyone know a real use-case for defining spacing on int (where the intention is not to cast them to floats)? Without a use case, I am in favor of going the deprecation route here I think. |
@eric-wieser @seberg I am not sure if there is a real use-case for this specific function. In that case, will it be better to simply change the document? If we change the document, do we need to raise errors/warnings for |
@kianasun, my comments about TypeResolving were more philosophical for a future change API change. We can deprecate using this functions on integers (it involves creating a new TypeResolver right now). |
close/reopen to retrigger shippable. |
When the
dtype
of the input isint
orbool
, the output ofnp.spacing
function was puzzling.