-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
BUG: Categoricals cannot compare to ndim=0 array values #8658
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
There's an inconsistency between comparison and arithmetical operations in numpy, I've reported it here. |
a numpy bug - say it's not so :) |
Sure looks like it to me. Regardless though, I think rank-0 arrays should be treated the same as their pure scalar counterparts. Is there a reason not to do that? |
that sounds right - not sure we can fix his without the upstream fix though ? |
Well, in numpy terms, scalar and zerodim array are different entities with their own properties. There were discussions about removing one of them in favour of the other, but AFAIC none has come to a solid decision to do so (here is an interesting summary). My fix thoughts were about the fact that there are de facto two ways of expressing a scalar value in numpy and there may be places in pandas where only one of those is handled properly. Pandas has a long history of fixing numpy's shortcomings, maybe this case should be another manifestation of "doing it right" principle. |
I agree with you in principle about an pd.isscalar - go for it if u have time would make indexing logic detection maybe a bit simpler |
Reproduction steps:
The problem is that when
cat[0]
is the first operand (type == np.int64
) it orchestrates the execution and the first step is casting it to a rank-0 array (it becomesarray(1)
rather thannp.int64(1)
) and at that point it ceases to passnp.isscalar
check and corresponding branch of execution is skipped.The fix is trivial, feel free to beat me to it.
On a broader scale, we might want to review all uses of
np.isscalar
and see if they can also benefit from accepting rank-0 arrays. If that's true, we might want to addpd.isscalar
function and use it everywhere instead.The text was updated successfully, but these errors were encountered: