1
1
#!/usr/bin/env python
2
2
3
- import functools
4
3
from itertools import product
5
4
from distutils .version import LooseVersion
6
5
7
6
import nose
8
- from nose .tools import assert_raises , assert_true , assert_false , assert_equal
7
+ from nose .tools import assert_raises
9
8
10
9
from numpy .random import randn , rand , randint
11
10
import numpy as np
@@ -887,7 +886,7 @@ def check_complex_series_frame_alignment(self, engine, parser):
887
886
expected = expected2 + df
888
887
889
888
res = pd .eval ('df2 + s + df' , engine = engine , parser = parser )
890
- assert_equal (res .shape , expected .shape )
889
+ tm . assert_equal (res .shape , expected .shape )
891
890
assert_frame_equal (res , expected )
892
891
893
892
@slow
@@ -930,13 +929,13 @@ def check_performance_warning_for_poor_alignment(self, engine, parser):
930
929
pd .eval ('df + s' , engine = engine , parser = parser )
931
930
932
931
if not is_python_engine :
933
- assert_equal (len (w ), 1 )
932
+ tm . assert_equal (len (w ), 1 )
934
933
msg = str (w [0 ].message )
935
934
expected = ("Alignment difference on axis {0} is larger"
936
935
" than an order of magnitude on term {1!r}, "
937
936
"by more than {2:.4g}; performance may suffer"
938
937
"" .format (1 , 'df' , np .log10 (s .size - df .shape [1 ])))
939
- assert_equal (msg , expected )
938
+ tm . assert_equal (msg , expected )
940
939
941
940
def test_performance_warning_for_poor_alignment (self ):
942
941
for engine , parser in ENGINES_PARSERS :
@@ -982,17 +981,17 @@ def test_simple_arith_ops(self):
982
981
else :
983
982
expec = _eval_single_bin (1 , op , 1 , self .engine )
984
983
x = self .eval (ex , engine = self .engine , parser = self .parser )
985
- assert_equal (x , expec )
984
+ tm . assert_equal (x , expec )
986
985
987
986
expec = _eval_single_bin (x , op , 1 , self .engine )
988
987
y = self .eval (ex2 , local_dict = {'x' : x }, engine = self .engine ,
989
988
parser = self .parser )
990
- assert_equal (y , expec )
989
+ tm . assert_equal (y , expec )
991
990
992
991
expec = _eval_single_bin (1 , op , x + 1 , self .engine )
993
992
y = self .eval (ex3 , local_dict = {'x' : x },
994
993
engine = self .engine , parser = self .parser )
995
- assert_equal (y , expec )
994
+ tm . assert_equal (y , expec )
996
995
997
996
def test_simple_bool_ops (self ):
998
997
for op , lhs , rhs in product (expr ._bool_ops_syms , (True , False ),
@@ -1024,7 +1023,7 @@ def test_4d_ndarray_fails(self):
1024
1023
1025
1024
def test_constant (self ):
1026
1025
x = self .eval ('1' )
1027
- assert_equal (x , 1 )
1026
+ tm . assert_equal (x , 1 )
1028
1027
1029
1028
def test_single_variable (self ):
1030
1029
df = DataFrame (randn (10 , 2 ))
@@ -1379,7 +1378,7 @@ def check_no_new_locals(self, engine, parser):
1379
1378
pd .eval ('x + 1' , local_dict = lcls , engine = engine , parser = parser )
1380
1379
lcls2 = locals ().copy ()
1381
1380
lcls2 .pop ('lcls' )
1382
- assert_equal (lcls , lcls2 )
1381
+ tm . assert_equal (lcls , lcls2 )
1383
1382
1384
1383
def test_no_new_locals (self ):
1385
1384
for engine , parser in product (_engines , expr ._parsers ):
@@ -1391,7 +1390,7 @@ def check_no_new_globals(self, engine, parser):
1391
1390
gbls = globals ().copy ()
1392
1391
pd .eval ('x + 1' , engine = engine , parser = parser )
1393
1392
gbls2 = globals ().copy ()
1394
- assert_equal (gbls , gbls2 )
1393
+ tm . assert_equal (gbls , gbls2 )
1395
1394
1396
1395
def test_no_new_globals (self ):
1397
1396
for engine , parser in product (_engines , expr ._parsers ):
@@ -1556,14 +1555,27 @@ def check_bool_ops_fails_on_scalars(gen, lhs, cmp, rhs, engine, parser):
1556
1555
def test_bool_ops_fails_on_scalars ():
1557
1556
_bool_ops_syms = 'and' , 'or'
1558
1557
dtypes = int , float
1559
- gen = {int : lambda : np .random .randint (10 ), float : np .random .randn }
1558
+ gen = {int : lambda : np .random .randint (10 ), float : np .random .randn }
1560
1559
for engine , parser , dtype1 , cmp , dtype2 in product (_engines , expr ._parsers ,
1561
1560
dtypes , _bool_ops_syms ,
1562
1561
dtypes ):
1563
1562
yield (check_bool_ops_fails_on_scalars , gen , gen [dtype1 ](), cmp ,
1564
1563
gen [dtype2 ](), engine , parser )
1565
1564
1566
1565
1566
+ def check_inf (engine , parser ):
1567
+ tm .skip_if_no_ne (engine )
1568
+ s = 'inf + 1'
1569
+ expected = np .inf
1570
+ result = pd .eval (s , engine = engine , parser = parser )
1571
+ tm .assert_equal (result , expected )
1572
+
1573
+
1574
+ def test_inf ():
1575
+ for engine , parser in ENGINES_PARSERS :
1576
+ yield check_inf , engine , parser
1577
+
1578
+
1567
1579
if __name__ == '__main__' :
1568
1580
nose .runmodule (argv = [__file__ , '-vvs' , '-x' , '--pdb' , '--pdb-failure' ],
1569
1581
exit = False )
0 commit comments