-
-
Notifications
You must be signed in to change notification settings - Fork 10.9k
BUG: For integer arguments, round
returns a view while ceil
returns a copy
#29124
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
Comments
I didn't realize round returned views. Ufuncs never do, right now. I think they could for new-style ufuncs, but they don't in practice. |
Which is exactly the issue with |
Ah, yeah, I would feel more safe just returning a copy for |
I agree this change is good to make. In principle, any change from view to copy or vice versa is a backwards compatibility break, but it this case it seems unlikely that it's going to bite anyone unless their code is already buggy. This looks like a bug rather than an intentional design choice.
@ev-br can you clarify what you mean here? I can interpret it as "the behavior in 1.2x was to always return a copy", or "this was changed for other functions in 2.0 and |
Meant the latter, sorry for not being clear. Consider
So
That the output dtype is now consistent is great. A small hiccup which this PR aims to fix is that The resulting inconsistency is probably not easy to find unless you're unlucky to hit it (and then it can be a bit of a chore to debug), or are specifically looking for it :-). The only reason I found it now was that I mistyped |
Describe the issue:
I expected that all of
ceil
,trunc
andround
always return either a view or a copy for all dtypes. However, for integer arguments,round
returns a view for integer inputs and a copy for float inputs.ceil
andfloor
all return a copy for both integers and floats.IIUC the return dtype was changed in numpy 2.0, so this looks like a small omission.
Reproduce the code example:
Error message:
.
Python and NumPy Versions:
Runtime Environment:
Context for the issue:
Found in data-apis/array-api-compat#333 which aims to make sure that
array_api_compat.numpy
does not change the view/copy semantics ofnumpy
itself.The text was updated successfully, but these errors were encountered: