-
-
Notifications
You must be signed in to change notification settings - Fork 10.8k
BUG: (closes #4352) any and all applied to object arrays should return bool #11857
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, unfortunately this misses the arr.any()
. There are also C-level equivalent functions IIRC, so those should be fixed up as well :/. Although it seems that numpy.core._methods
includes _any
so it is probably easy to give it a similar treatment (in python code).
Overall, while it seems easy, I am not sure this is actually easy to get right.
@seberg thanks for the review. Right now |
To be a bit more clear, what about:
```
np.any(np.array([1.5, 2.4], dtype=object))
np.any(np.array([object(), 2.4], dtype=object))
```
and horrifying:
```
np.any(np.array([np.array([3]), 2.4], dtype=object))
```
which gives back an array that is actually an item (because tat array,
can be converted by `bool()`, grrrr...
|
Ah, random realization, `dtype=np.bool_` probably works, although it
will probably cast all inputs to bool from the start (and not just
force output dtype selection I think). On the other hand, that casting
probably already occurs for all but object dtype, since the ufunc is
typed `dd->?`, and reductions need all the same, so they force `??->?`
probably, so giving dtype will not change anything for them currently.
|
so what would be expected if it's |
unfortunately dtype is not supported in |
[citation needed]. Just change
to
|
As far as I know, it's impossible in python for I think the way to go here would be:
|
@eric-wieser I have tried that and it causes an error in the
should be without the dtype |
I don't understand what you mean. What error do you get if you make the change I proposed above? |
@eric-wieser the error would be as follow:
|
What is |
|
Then |
I think it also happened to |
Perhaps this PR should come in two parts then - adding support for a |
Doing the first step would be very nice in any caes maybe (though did not think about it too much). We also have to worry a bit about changing someone code. I am not really worried about it, but I don't see a nice way to warn here. EDIT: Sorry that numpy has "traps" like this. Things sometimes look easy on first sight and then get sticky very fast when it gets being careful about breaking things and just the details. |
Ok, I will give part 1 a try then. I will leave it here after I finish part 1 then. Thanks for being patient with me and giving advice. |
The problem was pin pointed, in
For which is implemented in
which is mimicking the python |
I think #11857 (comment) is a simple fix that will work. If needed, I can make a PR. |
Any progress on this? What's the tldr of the discussion so far? Thanks ! |
@Cheukting I resolved the merge conflicts and rebased to get a sense of what's going on with this. Locally all tests pass for me. Argh, I was almost done writing a really long comment, and now I lost it due to a UI glitch. Let me summarize only:
|
I think >>> 4 and np
<module 'numpy' from '/home/rgommers/code/numpy/numpy/__init__.py'>
>>> all([3, 4, np, [1]])
True |
Hi, @rgommers sorry I was having some issues with my computer yesterday so I have not much progress. I will try again this coming weekend and let you know how it goes. Thanks for helping me out. |
That's too bad, the sprint was fun! Anyway, I'll keep an eye on this, would be nice to get it merged:) |
@Cheukting This needs a rebase. |
Hi @charris Thanks for reminding me about this. I am afraid this is too old and would not be relevant anymore. I am happy to close it. Looking forward to work on something else in the future :-) |
Still very relevant, but we should maybe decide whether we want to change this for any/all, or directly in |
Ok, I will reopen and rebase it to keep this discussion. However, I would need more information and guidance to move forward. I would really love to get this done and move on 😅 |
We need to make a decision, lets see if we can manage in the next triage meeting. My suspicion is that:
|
Mailing list ping to see if anyone voices concerns about trying this: https://mail.python.org/archives/list/[email protected]/thread/6JE4FGYCRTCURGPSDZV4X7HKY77PUZMU/ I need to take a closer look, because right now I am confused about the |
@seberg would you mind taking a look again or guiding @Cheukting through on what needs to be done here? If the best idea is to start from scratch or for someone else to take over, that is ok too. Cheers! |
OK, lets close it... We could aim for In either case, this doesn't look terrible or should be complicated. The We can add (I am not convicned that any/all need |
BUG: (closes #4352) numpy any and all applied to object arrays should return bool
Fix problem of np.any and np.all not always return bool.
(from EuroSciPy 2018 sprints)