@@ -129,8 +129,8 @@ def setup_data(self):
129
129
Series ([1 , 2 , np .nan , np .nan , 5 ]), nan_df1 )
130
130
self .pandas_rhses = (DataFrame (randn (10 , 5 )), Series (randn (5 )),
131
131
Series ([1 , 2 , np .nan , np .nan , 5 ]), nan_df2 )
132
- self .scalar_lhses = randn (), np . float64 ( randn ()), np . nan
133
- self .scalar_rhses = randn (), np . float64 ( randn ()), np . nan
132
+ self .scalar_lhses = randn (),
133
+ self .scalar_rhses = randn (),
134
134
135
135
self .lhses = self .pandas_lhses + self .scalar_lhses
136
136
self .rhses = self .pandas_rhses + self .scalar_rhses
@@ -180,7 +180,6 @@ def test_floor_division(self):
180
180
for lhs , rhs in product (self .lhses , self .rhses ):
181
181
self .check_floor_division (lhs , '//' , rhs )
182
182
183
- @slow
184
183
def test_pow (self ):
185
184
for lhs , rhs in product (self .lhses , self .rhses ):
186
185
self .check_pow (lhs , '**' , rhs )
@@ -198,13 +197,13 @@ def test_compound_invert_op(self):
198
197
@slow
199
198
def test_chained_cmp_op (self ):
200
199
mids = self .lhses
201
- cmp_ops = tuple (set (self .cmp_ops ) - set (['==' , '!=' , '<=' , '>=' ]))
200
+ cmp_ops = '<' , '>' # tuple(set(self.cmp_ops) - set(['==', '!=', '<=', '>=']))
202
201
for lhs , cmp1 , mid , cmp2 , rhs in product (self .lhses , cmp_ops ,
203
202
mids , cmp_ops , self .rhses ):
204
203
self .check_chained_cmp_op (lhs , cmp1 , mid , cmp2 , rhs )
205
204
206
205
def check_complex_cmp_op (self , lhs , cmp1 , rhs , binop , cmp2 ):
207
- skip_these = 'in' , 'not in'
206
+ skip_these = _scalar_skip
208
207
ex = '(lhs {cmp1} rhs) {binop} (lhs {cmp2} rhs)' .format (cmp1 = cmp1 ,
209
208
binop = binop ,
210
209
cmp2 = cmp2 )
@@ -264,7 +263,7 @@ def check_complex_cmp_op(self, lhs, cmp1, rhs, binop, cmp2):
264
263
265
264
@skip_incompatible_operand
266
265
def check_chained_cmp_op (self , lhs , cmp1 , mid , cmp2 , rhs ):
267
- skip_these = 'in' , 'not in'
266
+ skip_these = _scalar_skip
268
267
269
268
def check_operands (left , right , cmp_op ):
270
269
if (np .isscalar (left ) and np .isnan (left ) and not np .isscalar (right )
@@ -318,11 +317,7 @@ def check_operands(left, right, cmp_op):
318
317
ex1 = 'lhs {0} mid {1} rhs' .format (cmp1 , cmp2 )
319
318
ex2 = 'lhs {0} mid and mid {1} rhs' .format (cmp1 , cmp2 )
320
319
ex3 = '(lhs {0} mid) & (mid {1} rhs)' .format (cmp1 , cmp2 )
321
- try :
322
- expected = _eval_single_bin (lhs_new , '&' , rhs_new , self .engine )
323
- except TypeError :
324
- import ipdb ; ipdb .set_trace ()
325
- raise
320
+ expected = _eval_single_bin (lhs_new , '&' , rhs_new , self .engine )
326
321
327
322
for ex in (ex1 , ex2 , ex3 ):
328
323
result = pd .eval (ex , engine = self .engine ,
@@ -729,9 +724,8 @@ def setup_ops(self):
729
724
730
725
def check_chained_cmp_op (self , lhs , cmp1 , mid , cmp2 , rhs ):
731
726
ex1 = 'lhs {0} mid {1} rhs' .format (cmp1 , cmp2 )
732
- self .assertRaises (NotImplementedError , pd .eval , ex1 ,
733
- local_dict = {'lhs' : lhs , 'mid' : mid , 'rhs' : rhs },
734
- engine = self .engine , parser = self .parser )
727
+ with tm .assertRaises (NotImplementedError ):
728
+ pd .eval (ex1 , engine = self .engine , parser = self .parser )
735
729
736
730
737
731
class TestEvalPythonPython (TestEvalNumexprPython ):
@@ -783,7 +777,8 @@ def check_chained_cmp_op(self, lhs, cmp1, mid, cmp2, rhs):
783
777
784
778
class TestAlignment (object ):
785
779
786
- index_types = 'i' , 'f' , 's' , 'u' , 'dt' , # 'p'
780
+ index_types = 'i' , 'u' , 'dt'
781
+ lhs_index_types = index_types + ('f' , 's' ) # 'p'
787
782
788
783
def check_align_nested_unary_op (self , engine , parser ):
789
784
skip_if_no_ne (engine )
@@ -798,23 +793,23 @@ def test_align_nested_unary_op(self):
798
793
799
794
def check_basic_frame_alignment (self , engine , parser ):
800
795
skip_if_no_ne (engine )
801
- args = product (self .index_types , repeat = 2 )
802
- for r_idx_type , c_idx_type in args :
803
- df = mkdf (10 , 10 , data_gen_f = f , r_idx_type = r_idx_type ,
796
+ args = product (self .lhs_index_types , self .index_types ,
797
+ self .index_types )
798
+ for lr_idx_type , rr_idx_type , c_idx_type in args :
799
+ df = mkdf (10 , 10 , data_gen_f = f , r_idx_type = lr_idx_type ,
804
800
c_idx_type = c_idx_type )
805
- df2 = mkdf (20 , 10 , data_gen_f = f , r_idx_type = r_idx_type ,
801
+ df2 = mkdf (20 , 10 , data_gen_f = f , r_idx_type = rr_idx_type ,
806
802
c_idx_type = c_idx_type )
807
803
res = pd .eval ('df + df2' , engine = engine , parser = parser )
808
804
assert_frame_equal (res , df + df2 )
809
805
810
- @slow
811
806
def test_basic_frame_alignment (self ):
812
807
for engine , parser in ENGINES_PARSERS :
813
808
yield self .check_basic_frame_alignment , engine , parser
814
809
815
810
def check_frame_comparison (self , engine , parser ):
816
811
skip_if_no_ne (engine )
817
- args = product (self .index_types , repeat = 2 )
812
+ args = product (self .lhs_index_types , repeat = 2 )
818
813
for r_idx_type , c_idx_type in args :
819
814
df = mkdf (10 , 10 , data_gen_f = f , r_idx_type = r_idx_type ,
820
815
c_idx_type = c_idx_type )
@@ -826,18 +821,19 @@ def check_frame_comparison(self, engine, parser):
826
821
res = pd .eval ('df < df3' , engine = engine , parser = parser )
827
822
assert_frame_equal (res , df < df3 )
828
823
829
- @slow
830
824
def test_frame_comparison (self ):
831
825
for engine , parser in ENGINES_PARSERS :
832
826
yield self .check_frame_comparison , engine , parser
833
827
834
828
def check_medium_complex_frame_alignment (self , engine , parser ):
835
829
skip_if_no_ne (engine )
836
- args = product (self .index_types , repeat = 4 )
830
+ args = product (self .lhs_index_types , self .index_types ,
831
+ self .index_types , self .index_types )
832
+
837
833
for r1 , c1 , r2 , c2 in args :
838
- df = mkdf (5 , 2 , data_gen_f = f , r_idx_type = r1 , c_idx_type = c1 )
839
- df2 = mkdf (10 , 2 , data_gen_f = f , r_idx_type = r2 , c_idx_type = c2 )
840
- df3 = mkdf (15 , 2 , data_gen_f = f , r_idx_type = r2 , c_idx_type = c2 )
834
+ df = mkdf (3 , 2 , data_gen_f = f , r_idx_type = r1 , c_idx_type = c1 )
835
+ df2 = mkdf (4 , 2 , data_gen_f = f , r_idx_type = r2 , c_idx_type = c2 )
836
+ df3 = mkdf (5 , 2 , data_gen_f = f , r_idx_type = r2 , c_idx_type = c2 )
841
837
res = pd .eval ('df + df2 + df3' , engine = engine , parser = parser )
842
838
assert_frame_equal (res , df + df2 + df3 )
843
839
@@ -864,20 +860,19 @@ def testit(r_idx_type, c_idx_type, index_name):
864
860
expected = df + s
865
861
assert_frame_equal (res , expected )
866
862
867
- args = product (self .index_types , self .index_types , ( 'index' ,
868
- 'columns' ))
863
+ args = product (self .lhs_index_types , self .index_types ,
864
+ ( 'index' , 'columns' ))
869
865
for r_idx_type , c_idx_type , index_name in args :
870
866
testit (r_idx_type , c_idx_type , index_name )
871
867
872
- @slow
873
868
def test_basic_frame_series_alignment (self ):
874
869
for engine , parser in ENGINES_PARSERS :
875
870
yield self .check_basic_frame_series_alignment , engine , parser
876
871
877
872
def check_basic_series_frame_alignment (self , engine , parser ):
878
873
skip_if_no_ne (engine )
879
874
def testit (r_idx_type , c_idx_type , index_name ):
880
- df = mkdf (10 , 10 , data_gen_f = f , r_idx_type = r_idx_type ,
875
+ df = mkdf (10 , 7 , data_gen_f = f , r_idx_type = r_idx_type ,
881
876
c_idx_type = c_idx_type )
882
877
index = getattr (df , index_name )
883
878
s = Series (np .random .randn (5 ), index [:5 ])
@@ -892,19 +887,18 @@ def testit(r_idx_type, c_idx_type, index_name):
892
887
expected = s + df
893
888
assert_frame_equal (res , expected )
894
889
895
- args = product (self .index_types , self .index_types , ( 'index' ,
896
- 'columns' ))
890
+ args = product (self .lhs_index_types , self .index_types ,
891
+ ( 'index' , 'columns' ))
897
892
for r_idx_type , c_idx_type , index_name in args :
898
893
testit (r_idx_type , c_idx_type , index_name )
899
894
900
- @slow
901
895
def test_basic_series_frame_alignment (self ):
902
896
for engine , parser in ENGINES_PARSERS :
903
897
yield self .check_basic_series_frame_alignment , engine , parser
904
898
905
899
def check_series_frame_commutativity (self , engine , parser ):
906
900
skip_if_no_ne (engine )
907
- args = product (self .index_types , self .index_types , ('+' , '*' ),
901
+ args = product (self .lhs_index_types , self .index_types , ('+' , '*' ),
908
902
('index' , 'columns' ))
909
903
for r_idx_type , c_idx_type , op , index_name in args :
910
904
df = mkdf (10 , 10 , data_gen_f = f , r_idx_type = r_idx_type ,
@@ -921,20 +915,28 @@ def check_series_frame_commutativity(self, engine, parser):
921
915
if engine == 'numexpr' :
922
916
assert_frame_equal (a , b )
923
917
924
- @slow
925
918
def test_series_frame_commutativity (self ):
926
919
for engine , parser in ENGINES_PARSERS :
927
920
yield self .check_series_frame_commutativity , engine , parser
928
921
929
922
def check_complex_series_frame_alignment (self , engine , parser ):
930
923
skip_if_no_ne (engine )
931
- index_types = [self .index_types ] * 4
932
- args = product (('index' , 'columns' ), ('df' , 'df2' ), * index_types )
933
- for index_name , obj , r1 , r2 , c1 , c2 in args :
934
- df = mkdf (10 , 5 , data_gen_f = f , r_idx_type = r1 , c_idx_type = c1 )
935
- df2 = mkdf (20 , 5 , data_gen_f = f , r_idx_type = r2 , c_idx_type = c2 )
936
- index = getattr (locals ()[obj ], index_name )
937
- s = Series (np .random .randn (5 ), index [:5 ])
924
+
925
+ import random
926
+ args = product (self .lhs_index_types , self .index_types ,
927
+ self .index_types , self .index_types )
928
+ n = 3
929
+ m1 = 5
930
+ m2 = 2 * m1
931
+
932
+ for r1 , r2 , c1 , c2 in args :
933
+ index_name = random .choice (['index' , 'columns' ])
934
+ obj_name = random .choice (['df' , 'df2' ])
935
+
936
+ df = mkdf (m1 , n , data_gen_f = f , r_idx_type = r1 , c_idx_type = c1 )
937
+ df2 = mkdf (m2 , n , data_gen_f = f , r_idx_type = r2 , c_idx_type = c2 )
938
+ index = getattr (locals ().get (obj_name ), index_name )
939
+ s = Series (np .random .randn (n ), index [:n ])
938
940
939
941
if r2 == 'dt' or c2 == 'dt' :
940
942
if engine == 'numexpr' :
@@ -1004,7 +1006,6 @@ def check_performance_warning_for_poor_alignment(self, engine, parser):
1004
1006
"" .format (1 , 's' , np .log10 (s .size - df .shape [1 ])))
1005
1007
assert_equal (msg , expected )
1006
1008
1007
-
1008
1009
def test_performance_warning_for_poor_alignment (self ):
1009
1010
for engine , parser in ENGINES_PARSERS :
1010
1011
yield self .check_performance_warning_for_poor_alignment , engine , parser
0 commit comments