pydata/pandas — pull request #6243 by cgohlke (2014-02-03 21:08:43+00:00)
Title: ENH: add support for Python 3.4 ast.NameConstant

Python 3.4 created a "NameConstant AST class to represent None, True, and False literals" (http://docs.python.org/3.4/whatsnew/changelog.html).
Pandas-0.13.1.win-amd64-py3.4 fails a few tests with `AttributeError: '...ExprVisitor' object has no attribute 'visit_NameConstant'`.
The suggested change fixes those test errors but I am not sure that it is the best/correct fix.

```
======================================================================
ERROR: test_scalar_unary (pandas.computation.tests.test_eval.TestEvalNumexprPandas)
----------------------------------------------------------------------
Traceback (most recent call last):
File "X:\Python34\lib\site-packages\pandas\computation\tests\test_eval.py", line 678, in test_scalar_unary
pd.eval('~True', parser=self.parser, engine=self.engine), ~True)
File "X:\Python34\lib\site-packages\pandas\computation\eval.py", line 207, in eval
truediv=truediv)
File "X:\Python34\lib\site-packages\pandas\computation\expr.py", line 762, in __init__
self.terms = self.parse()
File "X:\Python34\lib\site-packages\pandas\computation\expr.py", line 781, in parse
return self._visitor.visit(self.expr)
File "X:\Python34\lib\site-packages\pandas\computation\expr.py", line 449, in visit
return visitor(node, **kwargs)
File "X:\Python34\lib\site-packages\pandas\computation\expr.py", line 455, in visit_Module
return self.visit(expr, **kwargs)
File "X:\Python34\lib\site-packages\pandas\computation\expr.py", line 449, in visit
return visitor(node, **kwargs)
File "X:\Python34\lib\site-packages\pandas\computation\expr.py", line 458, in visit_Expr
return self.visit(node.value, **kwargs)
File "X:\Python34\lib\site-packages\pandas\computation\expr.py", line 449, in visit
return visitor(node, **kwargs)
File "X:\Python34\lib\site-packages\pandas\computation\expr.py", line 545, in visit_UnaryOp
operand = self.visit(node.operand)
File "X:\Python34\lib\site-packages\pandas\computation\expr.py", line 448, in visit
visitor = getattr(self, method)
AttributeError: 'PandasExprVisitor' object has no attribute 'visit_NameConstant'

======================================================================
ERROR: test_scalar_unary (pandas.computation.tests.test_eval.TestEvalNumexprPython)
----------------------------------------------------------------------
Traceback (most recent call last):
File "X:\Python34\lib\site-packages\pandas\computation\tests\test_eval.py", line 678, in test_scalar_unary
pd.eval('~True', parser=self.parser, engine=self.engine), ~True)
File "X:\Python34\lib\site-packages\pandas\computation\eval.py", line 207, in eval
truediv=truediv)
File "X:\Python34\lib\site-packages\pandas\computation\expr.py", line 762, in __init__
self.terms = self.parse()
File "X:\Python34\lib\site-packages\pandas\computation\expr.py", line 781, in parse
return self._visitor.visit(self.expr)
File "X:\Python34\lib\site-packages\pandas\computation\expr.py", line 449, in visit
return visitor(node, **kwargs)
File "X:\Python34\lib\site-packages\pandas\computation\expr.py", line 455, in visit_Module
return self.visit(expr, **kwargs)
File "X:\Python34\lib\site-packages\pandas\computation\expr.py", line 449, in visit
return visitor(node, **kwargs)
File "X:\Python34\lib\site-packages\pandas\computation\expr.py", line 458, in visit_Expr
return self.visit(node.value, **kwargs)
File "X:\Python34\lib\site-packages\pandas\computation\expr.py", line 449, in visit
return visitor(node, **kwargs)
File "X:\Python34\lib\site-packages\pandas\computation\expr.py", line 545, in visit_UnaryOp
operand = self.visit(node.operand)
File "X:\Python34\lib\site-packages\pandas\computation\expr.py", line 448, in visit
visitor = getattr(self, method)
AttributeError: 'PythonExprVisitor' object has no attribute 'visit_NameConstant'

======================================================================
ERROR: test_scalar_unary (pandas.computation.tests.test_eval.TestEvalPythonPandas)
----------------------------------------------------------------------
Traceback (most recent call last):
File "X:\Python34\lib\site-packages\pandas\computation\tests\test_eval.py", line 678, in test_scalar_unary
pd.eval('~True', parser=self.parser, engine=self.engine), ~True)
File "X:\Python34\lib\site-packages\pandas\computation\eval.py", line 207, in eval
truediv=truediv)
File "X:\Python34\lib\site-packages\pandas\computation\expr.py", line 762, in __init__
self.terms = self.parse()
File "X:\Python34\lib\site-packages\pandas\computation\expr.py", line 781, in parse
return self._visitor.visit(self.expr)
File "X:\Python34\lib\site-packages\pandas\computation\expr.py", line 449, in visit
return visitor(node, **kwargs)
File "X:\Python34\lib\site-packages\pandas\computation\expr.py", line 455, in visit_Module
return self.visit(expr, **kwargs)
File "X:\Python34\lib\site-packages\pandas\computation\expr.py", line 449, in visit
return visitor(node, **kwargs)
File "X:\Python34\lib\site-packages\pandas\computation\expr.py", line 458, in visit_Expr
return self.visit(node.value, **kwargs)
File "X:\Python34\lib\site-packages\pandas\computation\expr.py", line 449, in visit
return visitor(node, **kwargs)
File "X:\Python34\lib\site-packages\pandas\computation\expr.py", line 545, in visit_UnaryOp
operand = self.visit(node.operand)
File "X:\Python34\lib\site-packages\pandas\computation\expr.py", line 448, in visit
visitor = getattr(self, method)
AttributeError: 'PandasExprVisitor' object has no attribute 'visit_NameConstant'

======================================================================
ERROR: test_scalar_unary (pandas.computation.tests.test_eval.TestEvalPythonPython)
----------------------------------------------------------------------
Traceback (most recent call last):
File "X:\Python34\lib\site-packages\pandas\computation\tests\test_eval.py", line 678, in test_scalar_unary
pd.eval('~True', parser=self.parser, engine=self.engine), ~True)
File "X:\Python34\lib\site-packages\pandas\computation\eval.py", line 207, in eval
truediv=truediv)
File "X:\Python34\lib\site-packages\pandas\computation\expr.py", line 762, in __init__
self.terms = self.parse()
File "X:\Python34\lib\site-packages\pandas\computation\expr.py", line 781, in parse
return self._visitor.visit(self.expr)
File "X:\Python34\lib\site-packages\pandas\computation\expr.py", line 449, in visit
return visitor(node, **kwargs)
File "X:\Python34\lib\site-packages\pandas\computation\expr.py", line 455, in visit_Module
return self.visit(expr, **kwargs)
File "X:\Python34\lib\site-packages\pandas\computation\expr.py", line 449, in visit
return visitor(node, **kwargs)
File "X:\Python34\lib\site-packages\pandas\computation\expr.py", line 458, in visit_Expr
return self.visit(node.value, **kwargs)
File "X:\Python34\lib\site-packages\pandas\computation\expr.py", line 449, in visit
return visitor(node, **kwargs)
File "X:\Python34\lib\site-packages\pandas\computation\expr.py", line 545, in visit_UnaryOp
operand = self.visit(node.operand)
File "X:\Python34\lib\site-packages\pandas\computation\expr.py", line 448, in visit
visitor = getattr(self, method)
AttributeError: 'PythonExprVisitor' object has no attribute 'visit_NameConstant'

======================================================================
ERROR: test_bool_ops_with_constants (pandas.computation.tests.test_eval.TestOperationsNumExprPandas)
----------------------------------------------------------------------
Traceback (most recent call last):
File "X:\Python34\lib\site-packages\pandas\computation\tests\test_eval.py", line 1086, in test_bool_ops_with_constants

res = self.eval(ex)
File "X:\Python34\lib\site-packages\pandas\computation\tests\test_eval.py", line 1046, in eval
return pd.eval(*args, **kwargs)
File "X:\Python34\lib\site-packages\pandas\computation\eval.py", line 207, in eval
truediv=truediv)
File "X:\Python34\lib\site-packages\pandas\computation\expr.py", line 762, in __init__
self.terms = self.parse()
File "X:\Python34\lib\site-packages\pandas\computation\expr.py", line 781, in parse
return self._visitor.visit(self.expr)
File "X:\Python34\lib\site-packages\pandas\computation\expr.py", line 449, in visit
return visitor(node, **kwargs)
File "X:\Python34\lib\site-packages\pandas\computation\expr.py", line 455, in visit_Module
return self.visit(expr, **kwargs)
File "X:\Python34\lib\site-packages\pandas\computation\expr.py", line 449, in visit
return visitor(node, **kwargs)
File "X:\Python34\lib\site-packages\pandas\computation\expr.py", line 458, in visit_Expr
return self.visit(node.value, **kwargs)
File "X:\Python34\lib\site-packages\pandas\computation\expr.py", line 449, in visit
return visitor(node, **kwargs)
File "X:\Python34\lib\site-packages\pandas\computation\expr.py", line 716, in visit_BoolOp
return reduce(visitor, operands)
File "X:\Python34\lib\site-packages\pandas\computation\expr.py", line 708, in visitor
lhs = self._try_visit_binop(x)
File "X:\Python34\lib\site-packages\pandas\computation\expr.py", line 704, in _try_visit_binop
return self.visit(bop)
File "X:\Python34\lib\site-packages\pandas\computation\expr.py", line 448, in visit
visitor = getattr(self, method)
AttributeError: 'PandasExprVisitor' object has no attribute 'visit_NameConstant'

======================================================================
ERROR: test_simple_bool_ops (pandas.computation.tests.test_eval.TestOperationsNumExprPandas)
----------------------------------------------------------------------
Traceback (most recent call last):
File "X:\Python34\lib\site-packages\pandas\computation\tests\test_eval.py", line 1078, in test_simple_bool_ops
res = self.eval(ex)
File "X:\Python34\lib\site-packages\pandas\computation\tests\test_eval.py", line 1046, in eval
return pd.eval(*args, **kwargs)
File "X:\Python34\lib\site-packages\pandas\computation\eval.py", line 207, in eval
truediv=truediv)
File "X:\Python34\lib\site-packages\pandas\computation\expr.py", line 762, in __init__
self.terms = self.parse()
File "X:\Python34\lib\site-packages\pandas\computation\expr.py", line 781, in parse
return self._visitor.visit(self.expr)
File "X:\Python34\lib\site-packages\pandas\computation\expr.py", line 449, in visit
return visitor(node, **kwargs)
File "X:\Python34\lib\site-packages\pandas\computation\expr.py", line 455, in visit_Module
return self.visit(expr, **kwargs)
File "X:\Python34\lib\site-packages\pandas\computation\expr.py", line 449, in visit
return visitor(node, **kwargs)
File "X:\Python34\lib\site-packages\pandas\computation\expr.py", line 458, in visit_Expr
return self.visit(node.value, **kwargs)
File "X:\Python34\lib\site-packages\pandas\computation\expr.py", line 449, in visit
return visitor(node, **kwargs)
File "X:\Python34\lib\site-packages\pandas\computation\expr.py", line 716, in visit_BoolOp
return reduce(visitor, operands)
File "X:\Python34\lib\site-packages\pandas\computation\expr.py", line 708, in visitor
lhs = self._try_visit_binop(x)
File "X:\Python34\lib\site-packages\pandas\computation\expr.py", line 704, in _try_visit_binop
return self.visit(bop)
File "X:\Python34\lib\site-packages\pandas\computation\expr.py", line 448, in visit
visitor = getattr(self, method)
AttributeError: 'PandasExprVisitor' object has no attribute 'visit_NameConstant'

======================================================================
ERROR: test_bool_ops_with_constants (pandas.computation.tests.test_eval.TestOperationsNumExprPython)
----------------------------------------------------------------------
Traceback (most recent call last):
File "X:\Python34\lib\site-packages\pandas\computation\tests\test_eval.py", line 1389, in test_bool_ops_with_constants

res = self.eval(ex)
File "X:\Python34\lib\site-packages\pandas\computation\tests\test_eval.py", line 1046, in eval
return pd.eval(*args, **kwargs)
File "X:\Python34\lib\site-packages\pandas\computation\eval.py", line 207, in eval
truediv=truediv)
File "X:\Python34\lib\site-packages\pandas\computation\expr.py", line 762, in __init__
self.terms = self.parse()
File "X:\Python34\lib\site-packages\pandas\computation\expr.py", line 781, in parse
return self._visitor.visit(self.expr)
File "X:\Python34\lib\site-packages\pandas\computation\expr.py", line 449, in visit
return visitor(node, **kwargs)
File "X:\Python34\lib\site-packages\pandas\computation\expr.py", line 455, in visit_Module
return self.visit(expr, **kwargs)
File "X:\Python34\lib\site-packages\pandas\computation\expr.py", line 449, in visit
return visitor(node, **kwargs)
File "X:\Python34\lib\site-packages\pandas\computation\expr.py", line 458, in visit_Expr
return self.visit(node.value, **kwargs)
File "X:\Python34\lib\site-packages\pandas\computation\expr.py", line 449, in visit
return visitor(node, **kwargs)
File "X:\Python34\lib\site-packages\pandas\computation\expr.py", line 536, in visit_BinOp
op, op_class, left, right = self._possibly_transform_eq_ne(node)
File "X:\Python34\lib\site-packages\pandas\computation\expr.py", line 492, in _possibly_transform_eq_ne
left = self.visit(node.left, side='left')
File "X:\Python34\lib\site-packages\pandas\computation\expr.py", line 448, in visit
visitor = getattr(self, method)
AttributeError: 'PythonExprVisitor' object has no attribute 'visit_NameConstant'

======================================================================
ERROR: test_bool_ops_with_constants (pandas.computation.tests.test_eval.TestOperationsPythonPandas)
----------------------------------------------------------------------
Traceback (most recent call last):
File "X:\Python34\lib\site-packages\pandas\computation\tests\test_eval.py", line 1086, in test_bool_ops_with_constants

res = self.eval(ex)
File "X:\Python34\lib\site-packages\pandas\computation\tests\test_eval.py", line 1046, in eval
return pd.eval(*args, **kwargs)
File "X:\Python34\lib\site-packages\pandas\computation\eval.py", line 207, in eval
truediv=truediv)
File "X:\Python34\lib\site-packages\pandas\computation\expr.py", line 762, in __init__
self.terms = self.parse()
File "X:\Python34\lib\site-packages\pandas\computation\expr.py", line 781, in parse
return self._visitor.visit(self.expr)
File "X:\Python34\lib\site-packages\pandas\computation\expr.py", line 449, in visit
return visitor(node, **kwargs)
File "X:\Python34\lib\site-packages\pandas\computation\expr.py", line 455, in visit_Module
return self.visit(expr, **kwargs)
File "X:\Python34\lib\site-packages\pandas\computation\expr.py", line 449, in visit
return visitor(node, **kwargs)
File "X:\Python34\lib\site-packages\pandas\computation\expr.py", line 458, in visit_Expr
return self.visit(node.value, **kwargs)
File "X:\Python34\lib\site-packages\pandas\computation\expr.py", line 449, in visit
return visitor(node, **kwargs)
File "X:\Python34\lib\site-packages\pandas\computation\expr.py", line 716, in visit_BoolOp
return reduce(visitor, operands)
File "X:\Python34\lib\site-packages\pandas\computation\expr.py", line 708, in visitor
lhs = self._try_visit_binop(x)
File "X:\Python34\lib\site-packages\pandas\computation\expr.py", line 704, in _try_visit_binop
return self.visit(bop)
File "X:\Python34\lib\site-packages\pandas\computation\expr.py", line 448, in visit
visitor = getattr(self, method)
AttributeError: 'PandasExprVisitor' object has no attribute 'visit_NameConstant'

======================================================================
ERROR: test_simple_bool_ops (pandas.computation.tests.test_eval.TestOperationsPythonPandas)
----------------------------------------------------------------------
Traceback (most recent call last):
File "X:\Python34\lib\site-packages\pandas\computation\tests\test_eval.py", line 1078, in test_simple_bool_ops
res = self.eval(ex)
File "X:\Python34\lib\site-packages\pandas\computation\tests\test_eval.py", line 1046, in eval
return pd.eval(*args, **kwargs)
File "X:\Python34\lib\site-packages\pandas\computation\eval.py", line 207, in eval
truediv=truediv)
File "X:\Python34\lib\site-packages\pandas\computation\expr.py", line 762, in __init__
self.terms = self.parse()
File "X:\Python34\lib\site-packages\pandas\computation\expr.py", line 781, in parse
return self._visitor.visit(self.expr)
File "X:\Python34\lib\site-packages\pandas\computation\expr.py", line 449, in visit
return visitor(node, **kwargs)
File "X:\Python34\lib\site-packages\pandas\computation\expr.py", line 455, in visit_Module
return self.visit(expr, **kwargs)
File "X:\Python34\lib\site-packages\pandas\computation\expr.py", line 449, in visit
return visitor(node, **kwargs)
File "X:\Python34\lib\site-packages\pandas\computation\expr.py", line 458, in visit_Expr
return self.visit(node.value, **kwargs)
File "X:\Python34\lib\site-packages\pandas\computation\expr.py", line 449, in visit
return visitor(node, **kwargs)
File "X:\Python34\lib\site-packages\pandas\computation\expr.py", line 716, in visit_BoolOp
return reduce(visitor, operands)
File "X:\Python34\lib\site-packages\pandas\computation\expr.py", line 708, in visitor
lhs = self._try_visit_binop(x)
File "X:\Python34\lib\site-packages\pandas\computation\expr.py", line 704, in _try_visit_binop
return self.visit(bop)
File "X:\Python34\lib\site-packages\pandas\computation\expr.py", line 448, in visit
visitor = getattr(self, method)
AttributeError: 'PandasExprVisitor' object has no attribute 'visit_NameConstant'

======================================================================
ERROR: test_bool_ops_with_constants (pandas.computation.tests.test_eval.TestOperationsPythonPython)
----------------------------------------------------------------------
Traceback (most recent call last):
File "X:\Python34\lib\site-packages\pandas\computation\tests\test_eval.py", line 1389, in test_bool_ops_with_constants

res = self.eval(ex)
File "X:\Python34\lib\site-packages\pandas\computation\tests\test_eval.py", line 1046, in eval
return pd.eval(*args, **kwargs)
File "X:\Python34\lib\site-packages\pandas\computation\eval.py", line 207, in eval
truediv=truediv)
File "X:\Python34\lib\site-packages\pandas\computation\expr.py", line 762, in __init__
self.terms = self.parse()
File "X:\Python34\lib\site-packages\pandas\computation\expr.py", line 781, in parse
return self._visitor.visit(self.expr)
File "X:\Python34\lib\site-packages\pandas\computation\expr.py", line 449, in visit
return visitor(node, **kwargs)
File "X:\Python34\lib\site-packages\pandas\computation\expr.py", line 455, in visit_Module
return self.visit(expr, **kwargs)
File "X:\Python34\lib\site-packages\pandas\computation\expr.py", line 449, in visit
return visitor(node, **kwargs)
File "X:\Python34\lib\site-packages\pandas\computation\expr.py", line 458, in visit_Expr
return self.visit(node.value, **kwargs)
File "X:\Python34\lib\site-packages\pandas\computation\expr.py", line 449, in visit
return visitor(node, **kwargs)
File "X:\Python34\lib\site-packages\pandas\computation\expr.py", line 536, in visit_BinOp
op, op_class, left, right = self._possibly_transform_eq_ne(node)
File "X:\Python34\lib\site-packages\pandas\computation\expr.py", line 492, in _possibly_transform_eq_ne
left = self.visit(node.left, side='left')
File "X:\Python34\lib\site-packages\pandas\computation\expr.py", line 448, in visit
visitor = getattr(self, method)
AttributeError: 'PythonExprVisitor' object has no attribute 'visit_NameConstant'

======================================================================
ERROR: test_select_dtypes (pandas.io.tests.test_pytables.TestHDFStore)
----------------------------------------------------------------------
Traceback (most recent call last):
File "X:\Python34\lib\site-packages\pandas\io\tests\test_pytables.py", line 2939, in test_select_dtypes
result = store.select('df', Term('boolv == %s' % str(v)), columns = ['A','boolv'])
File "X:\Python34\lib\site-packages\pandas\io\pytables.py", line 664, in select
auto_close=auto_close).get_values()
File "X:\Python34\lib\site-packages\pandas\io\pytables.py", line 1338, in get_values
results = self.func(self.start, self.stop)
File "X:\Python34\lib\site-packages\pandas\io\pytables.py", line 653, in func
columns=columns, **kwargs)
File "X:\Python34\lib\site-packages\pandas\io\pytables.py", line 3788, in read
if not self.read_axes(where=where, **kwargs):
File "X:\Python34\lib\site-packages\pandas\io\pytables.py", line 3047, in read_axes
self.selection = Selection(self, where=where, **kwargs)
File "X:\Python34\lib\site-packages\pandas\io\pytables.py", line 4263, in __init__
self.terms = self.generate(where)
File "X:\Python34\lib\site-packages\pandas\io\pytables.py", line 4276, in generate
return Expr(where, queryables=q, encoding=self.table.encoding)
File "X:\Python34\lib\site-packages\pandas\computation\pytables.py", line 518, in __init__
self.terms = self.parse()
File "X:\Python34\lib\site-packages\pandas\computation\expr.py", line 781, in parse
return self._visitor.visit(self.expr)
File "X:\Python34\lib\site-packages\pandas\computation\expr.py", line 449, in visit
return visitor(node, **kwargs)
File "X:\Python34\lib\site-packages\pandas\computation\expr.py", line 455, in visit_Module
return self.visit(expr, **kwargs)
File "X:\Python34\lib\site-packages\pandas\computation\expr.py", line 449, in visit
return visitor(node, **kwargs)
File "X:\Python34\lib\site-packages\pandas\computation\expr.py", line 458, in visit_Expr
return self.visit(node.value, **kwargs)
File "X:\Python34\lib\site-packages\pandas\computation\expr.py", line 449, in visit
return visitor(node, **kwargs)
File "X:\Python34\lib\site-packages\pandas\computation\expr.py", line 689, in visit_Compare
return self.visit(binop)
File "X:\Python34\lib\site-packages\pandas\computation\expr.py", line 449, in visit
return visitor(node, **kwargs)
File "X:\Python34\lib\site-packages\pandas\computation\expr.py", line 536, in visit_BinOp
op, op_class, left, right = self._possibly_transform_eq_ne(node)
File "X:\Python34\lib\site-packages\pandas\computation\expr.py", line 494, in _possibly_transform_eq_ne
right = self.visit(node.right, side='right')
File "X:\Python34\lib\site-packages\pandas\computation\expr.py", line 448, in visit
visitor = getattr(self, method)
AttributeError: 'ExprVisitor' object has no attribute 'visit_NameConstant'
```