More on Numexpr-unsupported objects

Ivan Vilata i Balaguer ivilata at carabos.com
Tue Nov 7 11:19:37 CST 2006


This is somehow related with this previous thread about raising
``TypeError`` on unsupported objects in Numexpr:
http://www.mail-archive.com/numpy-discussion@lists.sourceforge.net/msg03146.html

There is still a case where unsupported objects can get into expressions
without Numexpr noticing.  For instance:

>>> import numexpr
>>> numexpr.evaluate('[]')
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
  File "numexpr/compiler.py", line 594, in evaluate
    _names_cache[expr_key] = getExprNames(ex, context)
  File "numexpr/compiler.py", line 570, in getExprNames
    ast = expressionToAST(ex)
  File "numexpr/compiler.py", line 84, in expressionToAST
    this_ast = ASTNode(ex.astType, ex.astKind, ex.value,
AttributeError: 'list' object has no attribute 'astType'

The attached patch makes the error clearer and more consistent with the
error added in the aforementioned thread:

>>> import numpy
>>> import numexpr
>>> numexpr.evaluate('[]')
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
  File "numexpr/compiler.py", line 596, in evaluate
    _names_cache[expr_key] = getExprNames(ex, context)
  File "numexpr/compiler.py", line 571, in getExprNames
    ex = stringToExpression(text, {}, context)
  File "numexpr/compiler.py", line 229, in stringToExpression
    raise TypeError("unsupported expression type: %s" % type(ex))
TypeError: unsupported expression type: <type 'list'>

Though I admit it may be strange for this error to be triggered.

(I had a little mess with using ``expressions.ExpressionNode`` instead
of ``expr.ExpressionNode``...  I still don't see why the private copy of
the module is necessary.)

::

	Ivan Vilata i Balaguer   >qo<   http://www.carabos.com/
	       Cárabos Coop. V.  V  V   Enjoy Data
	                          ""
-------------- next part --------------
Index: compiler.py
===================================================================
--- compiler.py	(revisión: 2307)
+++ compiler.py	(copia de trabajo)
@@ -225,6 +225,8 @@
     ex = eval(c, names)
     if expressions.isConstant(ex):
         ex = expr.ConstantNode(ex, expressions.getKind(ex))
+    elif not isinstance(ex, expr.ExpressionNode):
+        raise TypeError("unsupported expression type: %s" % type(ex))
     return ex
 
 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 309 bytes
Desc: Digital signature
Url : http://projects.scipy.org/pipermail/numpy-discussion/attachments/20061107/bdf54192/attachment-0001.bin 
-------------- next part --------------
-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
-------------- next part --------------
_______________________________________________
Numpy-discussion mailing list
Numpy-discussion at lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/numpy-discussion


More information about the Numpy-discussion mailing list