2
2
"""
3
3
4
4
import ast
5
- import operator
6
- import sys
7
- import inspect
8
5
import tokenize
9
- import datetime
10
6
11
7
from functools import partial
12
8
21
17
from pandas .computation .ops import _reductions , _mathops , _LOCAL_TAG
22
18
from pandas .computation .ops import Op , BinOp , UnaryOp , Term , Constant , Div
23
19
from pandas .computation .ops import UndefinedVariableError , FuncNode
24
- from pandas .computation .scope import Scope , _ensure_scope
20
+ from pandas .computation .scope import Scope
25
21
26
22
27
23
def tokenize_string (source ):
@@ -381,9 +377,9 @@ def _possibly_evaluate_binop(self, op, op_class, lhs, rhs,
381
377
rhs .type ))
382
378
383
379
if self .engine != 'pytables' :
384
- if (res .op in _cmp_ops_syms
385
- and getattr (lhs , 'is_datetime' , False )
386
- or getattr (rhs , 'is_datetime' , False )):
380
+ if (res .op in _cmp_ops_syms and
381
+ getattr (lhs , 'is_datetime' , False ) or
382
+ getattr (rhs , 'is_datetime' , False )):
387
383
# all date ops must be done in python bc numexpr doesn't work
388
384
# well with NaT
389
385
return self ._possibly_eval (res , self .binary_ops )
@@ -392,8 +388,8 @@ def _possibly_evaluate_binop(self, op, op_class, lhs, rhs,
392
388
# "in"/"not in" ops are always evaluated in python
393
389
return self ._possibly_eval (res , eval_in_python )
394
390
elif self .engine != 'pytables' :
395
- if (getattr (lhs , 'return_type' , None ) == object
396
- or getattr (rhs , 'return_type' , None ) == object ):
391
+ if (getattr (lhs , 'return_type' , None ) == object or
392
+ getattr (rhs , 'return_type' , None ) == object ):
397
393
# evaluate "==" and "!=" in python if either of our operands
398
394
# has an object return type
399
395
return self ._possibly_eval (res , eval_in_python +
@@ -517,7 +513,8 @@ def visit_Attribute(self, node, **kwargs):
517
513
raise ValueError ("Invalid Attribute context {0}" .format (ctx .__name__ ))
518
514
519
515
def visit_Call_35 (self , node , side = None , ** kwargs ):
520
- """ in 3.5 the starargs attribute was changed to be more flexible, #11097 """
516
+ """ in 3.5 the starargs attribute was changed to be more flexible,
517
+ #11097 """
521
518
522
519
if isinstance (node .func , ast .Attribute ):
523
520
res = self .visit_Attribute (node .func )
@@ -541,7 +538,7 @@ def visit_Call_35(self, node, side=None, **kwargs):
541
538
542
539
if isinstance (res , FuncNode ):
543
540
544
- new_args = [ self .visit (arg ) for arg in node .args ]
541
+ new_args = [self .visit (arg ) for arg in node .args ]
545
542
546
543
if node .keywords :
547
544
raise TypeError ("Function \" {0}\" does not support keyword "
@@ -551,15 +548,17 @@ def visit_Call_35(self, node, side=None, **kwargs):
551
548
552
549
else :
553
550
554
- new_args = [ self .visit (arg ).value for arg in node .args ]
551
+ new_args = [self .visit (arg ).value for arg in node .args ]
555
552
556
553
for key in node .keywords :
557
554
if not isinstance (key , ast .keyword ):
558
555
raise ValueError ("keyword error in function call "
559
556
"'{0}'" .format (node .func .id ))
560
557
561
558
if key .arg :
562
- kwargs .append (ast .keyword (keyword .arg , self .visit (keyword .value )))
559
+ # TODO: bug?
560
+ kwargs .append (ast .keyword (
561
+ keyword .arg , self .visit (keyword .value ))) # noqa
563
562
564
563
return self .const_type (res (* new_args , ** kwargs ), self .env )
565
564
0 commit comments