numexpr
numexpr copied to clipboard
where function with implicit booleans
From [email protected] on October 09, 2011 05:15:28
The following edge cases is not correctly handled by the numexpr 'where' function. Basically, implicit booleans (using 1 as True) are not handled as they are handled in numpy.
import numexpr as ne import numpy as np
np.where(1, 2, 3) array(2)
ne.evaluate('where(1, 2, 3)') Traceback (most recent call last): ... ValueError: too many dimensions
a = np.array([1]) b = 2 c = 3 np.where(a, b, c) array([2])
ne.evaluate('where(a, b, c)') Traceback (most recent call last): ... NotImplementedError: couldn't find matching opcode for 'where_llll'
Original issue: http://code.google.com/p/numexpr/issues/detail?id=61
The first example in this issue was probably fixed by #287. Adding an explicit test for that would not hurt. The second example (which I guess is what was important to the original reporter) is probably not fixed.
NE2.6 doesn't seem to cast the first argument in the ternary to bool if it's not that dtype. This is also true of NE3, so probably a check an operation insertion should be implemented. The default behavoir is 'safe' casting which definitely doesn't allow for int -> bool casts.
Message to comment on stale issues. If none provided, will not mark issues stale