-
-
Notifications
You must be signed in to change notification settings - Fork 9.5k
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
BUG: application of np.sum on a python iterator should raise an error #23107
Comments
The result isn't exactly incorrect. Here is what's happening: >>> import numpy as np
>>> x = np.asarray(map(lambda x: x, [[1, 2], [1,2]]))
>>> x
array(<map object at 0x7f6e7064fe50>, dtype=object)
>>> x.shape
()
>>> x.sum()
<map object at 0x7f6e7064fe50> We've had the exact opposite request too - namely to make NumPy functions work on iterators. This is all a big design mistake and it would have been much better never to implement this. But it's not a bug. Now, can we deprecate it? Not sure. Probably though. It could be deprecated in 1.25.0 and then removed in 2.0. If you could do some digging to find the discussion where it was added, that would probably be helpful in figuring out the impact of a deprecation here. |
I have just found this: #15625 but there are links to other related issues too. Small note: also probably expressions like Thanks for looking at this! For me personally, the stricter behavior, the better. |
Thanks! That deprecation was also discussed in gh-15625 indeed, I commented there. For completion here as well, and I added a Deprecation in 1.25.0 and removal in 2.0 seems good to me. Let's see what others think. |
Since it was milestoned, I tried having a look at it a bit here: main...seberg:numpy:deprecate-iterables happy if anyone wants to look at it more. Some annoyances is that:
So, maybe nothing major, or maybe annoying small things that need an idea for a work-around like the |
Describe the issue:
E.g.:
Incorrect/unexpected result is returned and no error is raised. I would expect
np.sum
to do a type check and error out in this case.NOTE: There is something similar for generators already (although it is just a warning):
Reproduce the code example:
Error message:
Runtime information:
1.23.5
3.9.16 (main, Dec 7 2022, 01:12:08)
[GCC 11.3.0]
Context for the issue:
No response
The text was updated successfully, but these errors were encountered: