numexpr icon indicating copy to clipboard operation
numexpr copied to clipboard

Operators not defined in Expression

Open Uvar opened this issue 6 years ago • 3 comments

In expressions.py, class ExpressionNode:

line 451: if sys.version_info[0] < 3: div = div_op rdiv = binop('div', reversed=True)

All fine, but the operators are not defined for Python 3. Leading to unexpected behavior in conjunction with for instance the floor division operator //. Not that it is really necessary to define these particular div and rdiv, but I guess I'd like it if support for floor division can be added. Right now, it will raise "Unsupported operand type(s) for //: 'VariableNode' and 'VariableNode' "

Uvar avatar Nov 27 '17 13:11 Uvar

__floordiv__ is the dunder in the module operations so this isn't supported at all in NumExpr 2.6. After looking at it, I think the issue is somewhat more complicated than I would like because in C++ integer division is truncated, and in Python floor division is... floor division. This is something that's intended to be in NumExpr 3.0 but it doesn't work properly right now so I'll mull it over and implement something.

robbmcleod avatar Nov 29 '17 03:11 robbmcleod

If I were to be fine with a truncating integer division (since I only expect positive integers), would it be possible to access it?

cod3monk avatar Mar 14 '21 15:03 cod3monk

@cod3monk Not in the vanilla release numexpr, no.

robbmcleod avatar Mar 17 '21 00:03 robbmcleod

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

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