numexpr icon indicating copy to clipboard operation
numexpr copied to clipboard

where function with implicit booleans

Open FrancescAlted opened this issue 11 years ago • 2 comments

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

FrancescAlted avatar Jan 22 '14 10:01 FrancescAlted

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.

gdementen avatar Nov 06 '17 08:11 gdementen

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.

robbmcleod avatar Nov 06 '17 20:11 robbmcleod

Message to comment on stale issues. If none provided, will not mark issues stale

github-actions[bot] avatar Feb 24 '24 01:02 github-actions[bot]