<s> """<STR_LIT>""" <EOL> import abc <EOL> from pandas import compat <EOL> from pandas . compat import DeepChainMap , map <EOL> import pandas . core . common as com <EOL> import pandas . formats . printing as printing <EOL> from pandas . computation . align import _align , _reconstruct_object <EOL> from pandas . computation . ops import ( UndefinedVariableError , <EOL> _mathops , _reductions ) <EOL> _ne_builtins = frozenset ( _mathops + _reductions ) <EOL> class NumExprClobberingError ( NameError ) : <EOL> pass <EOL> def _check_ne_builtin_clash ( expr ) : <EOL> """<STR_LIT>""" <EOL> names = expr . names <EOL> overlap = names & _ne_builtins <EOL> if overlap : <EOL> s = '<STR_LIT:U+002CU+0020>' . join ( map ( repr , overlap ) ) <EOL> raise NumExprClobberingError ( '<STR_LIT>' <EOL> '<STR_LIT>' % ( expr , s ) ) <EOL> class AbstractEngine ( object ) : <EOL> """<STR_LIT>""" <EOL> __metaclass__ = abc . ABCMeta <EOL> has_neg_frac = False <EOL> def __init__ ( self , expr ) : <EOL> self . expr = expr <EOL> self . aligned_axes = None <EOL> self . result_type = None <EOL> def convert ( self ) : <EOL> """<STR_LIT>""" <EOL> return printing . pprint_thing ( self . expr ) <EOL> def evaluate ( self ) : <EOL> """<STR_LIT>""" <EOL> if not self . _is_aligned : <EOL> self . result_type , self . aligned_axes = _align ( self . expr . terms ) <EOL> res = self . _evaluate ( ) <EOL> return _reconstruct_object ( self . result_type , res , self . aligned_axes , <EOL> self . expr . terms . return_type ) <EOL> @ property <EOL> def _is_aligned ( self ) : <EOL> return self . aligned_axes is not None and self . result_type is not None <EOL> @ abc . abstractmethod <EOL> def _evaluate ( self ) : <EOL> """<STR_LIT>""" <EOL> pass <EOL> class NumExprEngine ( AbstractEngine ) : <EOL> """<STR_LIT>""" <EOL> has_neg_frac = True <EOL> def __init__ ( self , expr ) : <EOL> super ( NumExprEngine , self ) . __init__ ( expr ) <EOL> def convert ( self ) : <EOL> return str ( super ( NumExprEngine , self ) . convert ( ) ) <EOL> def _evaluate ( self ) : <EOL> import numexpr as ne <EOL> s = self . convert ( ) <EOL> try : <EOL> env = self . expr . env <EOL> scope = env . full_scope <EOL> truediv = scope [ '<STR_LIT>' ] <EOL> _check_ne_builtin_clash ( self . expr ) <EOL> return ne . evaluate ( s , local_dict = scope , truediv = truediv ) <EOL> except KeyError as e : <EOL> try : <EOL> msg = e . message <EOL> except AttributeError : <EOL> msg = compat . text_type ( e ) <EOL> raise UndefinedVariableError ( msg ) <EOL> class PythonEngine ( AbstractEngine ) : <EOL> """<STR_LIT>""" <EOL> has_neg_frac = False <EOL> def __init__ ( self , expr ) : <EOL> super ( PythonEngine , self ) . __init__ ( expr ) <EOL> def evaluate ( self ) : <EOL> return self . expr ( ) <EOL> def _evaluate ( self ) : <EOL> pass <EOL> _engines = { '<STR_LIT>' : NumExprEngine , '<STR_LIT>' : PythonEngine } </s>
