Skip to content

BUG/API: disallow boolean arithmetic operations #6803

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

Merged
merged 3 commits into from
Apr 5, 2014
Merged

BUG/API: disallow boolean arithmetic operations #6803

merged 3 commits into from
Apr 5, 2014

Conversation

cpcloud
Copy link
Member

@cpcloud cpcloud commented Apr 4, 2014

closes #6762

@jreback jreback added this to the 0.14.0 milestone Apr 4, 2014
@jreback
Copy link
Contributor

jreback commented Apr 4, 2014

cool...merge on green

@cpcloud
Copy link
Member Author

cpcloud commented Apr 4, 2014

crap just realized this will fail on py3 ... operator.div isn't there anymore only truediv

@cpcloud
Copy link
Member Author

cpcloud commented Apr 4, 2014

less trivial than i thought ... will finish in a bit

cpcloud added a commit that referenced this pull request Apr 5, 2014
BUG/API: disallow boolean arithmetic operations
@cpcloud cpcloud merged commit fe9aa12 into pandas-dev:master Apr 5, 2014
@cpcloud cpcloud deleted the bool-arith-ops-6762 branch April 5, 2014 20:18
@jorisvandenbossche
Copy link
Member

@cpcloud @jreback I know this is already merged some time, but just stumbled on this. Is there a good reason to disallow this? Because it is an API change (so people could rely on this behaviour), and it does also work in numpy this way (at least for + and *).

@jreback
Copy link
Contributor

jreback commented Apr 19, 2014

no this only disallowing silly things

True + True
True * True works but you should just use &

@jorisvandenbossche
Copy link
Member

Is this silly?

In [18]: pd.__version__
Out[18]: '0.13.0'
In [19]: s = pd.Series(range(5))
In [20]: (s > 1) * (s < 3)
Out[20]:
0    False
1    False
2     True
3    False
4    False
dtype: bool

I know we say: just use & instead. And no problem at all that is the recommended way.
But above code now fails, while it was working previously. So potentially people could rely on this. Certainly given it also works this way in numpy:

In [21]: (s.values > 1) * (s.values < 3)
Out[21]: array([False, False,  True, False, False], dtype=bool)

So I was just wondering if there is a good reason to disallow this, apart from "people should use &"

@jreback
Copy link
Contributor

jreback commented Apr 19, 2014

it breaks Numexpr and so will simply raise
if u r doing boolean ops you should use boolean operators

it will fail loudly

it didn't work before if the frame was big enough (and hit Numexpr)

@cpcloud
Copy link
Member Author

cpcloud commented Apr 19, 2014

this was disallowed because numexpr doesn't have the op codes to deal with ops like

Bool OP Bool -> Bool

where OP is a (non-bitwise) arithmetic operator (e.g., +, -, *, /). It should either fail across the board or work across the board (the board being either numexpr is used or it's not) but since numexpr doesn't work with those ops (IMHO rightly so) we have to make it fail. It shouldn't work for objects < some size threshold and then not work for larger objects

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Testing pandas testing functions or related to the test suite
Projects
None yet
Development

Successfully merging this pull request may close these issues.

numexpr 2.3.1 error with pandas 0.13.1
3 participants