30
30
_frame2 = DataFrame (np .random .randn (100 , 4 ), columns = list ('ABCD' ), dtype = 'float64' )
31
31
_mixed = DataFrame ({ 'A' : _frame ['A' ].copy (), 'B' : _frame ['B' ].astype ('float32' ), 'C' : _frame ['C' ].astype ('int64' ), 'D' : _frame ['D' ].astype ('int32' ) })
32
32
_mixed2 = DataFrame ({ 'A' : _frame2 ['A' ].copy (), 'B' : _frame2 ['B' ].astype ('float32' ), 'C' : _frame2 ['C' ].astype ('int64' ), 'D' : _frame2 ['D' ].astype ('int32' ) })
33
+ _integer = DataFrame (np .random .randint (1 , 100 , size = (10001 , 4 )), columns = list ('ABCD' ), dtype = 'int64' )
33
34
34
35
class TestExpressions (unittest .TestCase ):
35
36
@@ -41,7 +42,54 @@ def setUp(self):
41
42
self .frame2 = _frame2 .copy ()
42
43
self .mixed = _mixed .copy ()
43
44
self .mixed2 = _mixed2 .copy ()
44
-
45
+ self .integer = _integer .copy ()
46
+ self ._MIN_ELEMENTS = expr ._MIN_ELEMENTS
47
+
48
+ def tearDown (self ):
49
+ expr ._MIN_ELEMENTS = self ._MIN_ELEMENTS
50
+
51
+ @nose .tools .nottest
52
+ def run_arithmetic_test (self , df , assert_func , check_dtype = False ):
53
+ expr ._MIN_ELEMENTS = 0
54
+ operations = ['add' , 'sub' , 'mul' , 'truediv' ]
55
+ if not py3compat .PY3 :
56
+ operations .append ('div' )
57
+ for arith in operations :
58
+ op = getattr (operator , arith )
59
+ expr .set_use_numexpr (False )
60
+ expected = op (df , df )
61
+ expr .set_use_numexpr (True )
62
+ result = op (df , df )
63
+ try :
64
+ if check_dtype :
65
+ if arith == 'div' :
66
+ assert expected .dtype .kind == df .dtype .kind
67
+ if arith == 'truediv' :
68
+ assert expected .dtype .kind == 'f'
69
+ assert_func (expected , result )
70
+ except Exception :
71
+ print ("Failed test with operator %r" % op .__name__ )
72
+ raise
73
+
74
+ def test_integer_arithmetic (self ):
75
+ self .run_arithmetic_test (self .integer , assert_frame_equal )
76
+ self .run_arithmetic_test (self .integer .icol (0 ), assert_series_equal ,
77
+ check_dtype = True )
78
+
79
+ def test_float_arithemtic (self ):
80
+ self .run_arithmetic_test (self .frame , assert_frame_equal )
81
+ self .run_arithmetic_test (self .frame .icol (0 ), assert_series_equal ,
82
+ check_dtype = True )
83
+
84
+ def test_mixed_arithmetic (self ):
85
+ self .run_arithmetic_test (self .mixed , assert_frame_equal )
86
+ for col in self .mixed .columns :
87
+ self .run_arithmetic_test (self .mixed [col ], assert_series_equal )
88
+
89
+ def test_integer_with_zeros (self ):
90
+ self .integer *= np .random .randint (0 , 2 , size = np .shape (self .integer ))
91
+ self .run_arithmetic_test (self .integer , assert_frame_equal )
92
+ self .run_arithmetic_test (self .integer .icol (0 ), assert_series_equal )
45
93
46
94
def test_invalid (self ):
47
95
0 commit comments