numexpr
numexpr copied to clipboard
Problem with "and" (also, __nonzero__ should not be defined)
From [email protected] on December 12, 2009 04:23:42
a = numpy.array([1, 2, 1, 2, 1], dtype=numpy.int8) # or numpy.int32 b = numpy.array([1, 2, 3, 4, 1], dtype=numpy.int8) # or numpy.int32 numexpr.evaluate("(a==1) & (b>2)") array([False, False, True, False, False], dtype=bool)
All good so far. But, now, if we try to use "and" instead of "&":
numexpr.evaluate("(a==1) and (b>2)") array([False, False, True, True, False], dtype=bool)
Which isn't right. Seems as if only the RHS expression of the "and" is evaluated. Ie. the result given is just "b>2".
This on windows XP, python 2.5.
Original issue: http://code.google.com/p/numexpr/issues/detail?id=24
From [email protected] on December 13, 2009 19:21:34
Hmm. Looking again, I now see that "and" is not a supported operator.
So I guess this bug report now morphs into "I should get an error when I try to use an unsupported operator". As TimBot's easter egg says: "Errors should never pass silently."
From [email protected] on September 27, 2011 06:18:23
fixed in r5591638b532f . Numexpr now raises an exception in that case.
Status: Fixed
From [email protected] on November 06, 2011 02:16:57
Unfortunately, PyTables uses ExpressionNode
comparisons via __nonzero__
a lot internally (the failures can be seen in, for example, PyTables test unit test_queries.IndexedTableUsage13
), so I'm undoing this fix (in revision 18d29c5c2e64 ).
Not sure how to fix that without breaking PyTables (I suppose a refactoring of PyTables should be done in the future). I'll leave this open anyway.
Status: Accepted
From [email protected] on April 26, 2013 04:20:16
After Antonio Valentino agreeing on this, I'm re-introducing this fix for 2.1.
Status: Fixed
From [email protected] on September 27, 2013 01:05:30
Apparently people still use PyTables 2.4 a lot (see #115), so the __nonzero__
is commented again for branch 2.2 (it will remain commented for default branch).
Re-opening the ticket just to keep track of this and it should closed when numexpr would drop compatibility with PyTables < 3 completely.
Summary: Problem with "and" (also, nonzero should not be defined) (was: Problem with "and")
Status: Started
Closing as stale due to inactivity. Feel free to reopen.