Skip to content

regression: NotImplementedError: operator '*' not implemented for bool dtypes #7210

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

Closed
yarikoptic opened this issue May 22, 2014 · 27 comments · Fixed by #7245
Closed

regression: NotImplementedError: operator '*' not implemented for bool dtypes #7210

yarikoptic opened this issue May 22, 2014 · 27 comments · Fixed by #7245
Labels
Error Reporting Incorrect or improved errors from pandas
Milestone

Comments

@yarikoptic
Copy link
Contributor

seemed to work just fine (with 0.13.1) and I do not see why it should not if you are decorating numpy arrays here:

  File "/home/neurodebian/proj/numpy-vbench/vbench/vbench/analysis.py", line 83, in __call__
    Tts, Tps = ss.ttest_1samp(test_samples.timing, results.timing)
  File "/usr/lib/python2.7/dist-packages/scipy/stats/stats.py", line 2887, in ttest_1samp
    t = np.where((d==0)*(v==0), 1.0, t) #define t=0/0 = 1, identical mean, var
  File "/home/neurodebian/deb/gits/pkg-exppsy/pandas/pandas/core/ops.py", line 505, in wrapper
    return left._constructor(wrap_results(na_op(lvalues, rvalues)),
  File "/home/neurodebian/deb/gits/pkg-exppsy/pandas/pandas/core/ops.py", line 445, in na_op
    raise_on_error=True, **eval_kwargs)
  File "/home/neurodebian/deb/gits/pkg-exppsy/pandas/pandas/computation/expressions.py", line 196, in evaluate
    _bool_arith_check(op_str, a, b)
  File "/home/neurodebian/deb/gits/pkg-exppsy/pandas/pandas/computation/expressions.py", line 177, in _bool_arith_check
    "dtypes" % op_str)
NotImplementedError: operator '*' not implemented for bool dtypes
@jreback
Copy link
Contributor

jreback commented May 22, 2014

on purpose numexpr doesn't allow this and since that is heavily used are banning it.

should be using & for anding

@jreback
Copy link
Contributor

jreback commented May 22, 2014

discussions here: #7011, #6762, #7015

@jorisvandenbossche
Copy link
Member

Could that be added in the error message? (that you can use & instead)

@jreback
Copy link
Contributor

jreback commented May 22, 2014

sure...I don't think that's hard, FYI I don't think their is an analog for |, is there?

@cpcloud can you change that error message a bit?

@cpcloud
Copy link
Member

cpcloud commented May 22, 2014

Dure

@cpcloud
Copy link
Member

cpcloud commented May 22, 2014

I mean sure

@yarikoptic
Copy link
Contributor Author

oh well -- just don't get surprised then whenever people with stock scipy would complain that they can't even do a ttest now (whenever it was working before)... FWIW -- scipy has refactored that code I believe in v0.11.0b1~20^2, so only wheezy and precise (among sensible) would be affected.

@dsm054
Copy link
Contributor

dsm054 commented May 23, 2014

"sure...I don't think that's hard, FYI I don't think their is an analog for |, is there?"

Isn't that simply +?

@jreback
Copy link
Contributor

jreback commented May 23, 2014

its not +

True | True == True
True + True == 2

@cpcloud
Copy link
Member

cpcloud commented May 23, 2014

aha but:

In [2]: np.array([True]) + np.array([True])
Out[2]: array([ True], dtype=bool)

@jreback
Copy link
Contributor

jreback commented May 23, 2014

interesting.

@cpcloud another possibility is to try to detect these condition and then just do the eval in python space (which will work I guess), maybe with a warning?

@cpcloud
Copy link
Member

cpcloud commented May 23, 2014

i pretty much do that now ... but i raise instead of continuing on

@cpcloud
Copy link
Member

cpcloud commented May 23, 2014

so i'll change it

@dsm054
Copy link
Contributor

dsm054 commented May 23, 2014

I had the dtype=bool behaviour in mind, but even apart from that, while True != 2, bool(True) == bool(2) which (as we say here) is close enough for government work.

@jorisvandenbossche
Copy link
Member

What do we do with this one? Ideally this would be handled for 0.14 (as this is introduced in 0.14)

@cpcloud
Copy link
Member

cpcloud commented May 26, 2014

@jorisvandenbossche agreed i'll have something up tonight

@jreback
Copy link
Contributor

jreback commented May 26, 2014

maybe easiest to do a translation, warning then evaluate it?

@cpcloud
Copy link
Member

cpcloud commented May 26, 2014

yep something like:

if bool arith op: warn("don't do this") -> do_it_anyway()

@jreback jreback added this to the 0.14.0 milestone May 26, 2014
@jreback
Copy link
Contributor

jreback commented May 27, 2014

@cpcloud PR for this?

@cpcloud
Copy link
Member

cpcloud commented May 27, 2014

Yep sorry got a bit sidetracked practicing my talk. :) should have something by lunch.

@cpcloud
Copy link
Member

cpcloud commented May 27, 2014

so really this should just be *, + and -, since none of the others really make sense

@jreback
Copy link
Contributor

jreback commented May 27, 2014

yep

@cpcloud
Copy link
Member

cpcloud commented May 27, 2014

interesting never really figured out what x - y for bool does, it's actually xor:

In [58]: x, y = rand(10) > 0.5, rand(10) > 0.5

In [59]: np.all((x | y) & ~(x & y) == x - y)
Out[59]: True

@jreback
Copy link
Contributor

jreback commented May 27, 2014

x-y == x^y as well (which is the xor operator)

@cpcloud
Copy link
Member

cpcloud commented May 27, 2014

ah right ... thanks that helps actually (simplifies the error message)

@jreback
Copy link
Contributor

jreback commented May 27, 2014

thanks @cpcloud !

@cpcloud
Copy link
Member

cpcloud commented May 27, 2014

np happy to help

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Error Reporting Incorrect or improved errors from pandas
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants