@@ -3114,6 +3114,39 @@ def test_arith_mixed(self):
3114
3114
'B' : [2 , 4 , 6 ]})
3115
3115
assert_frame_equal (result , expected )
3116
3116
3117
+
3118
+ def test_arith_getitem_commute (self ):
3119
+ df = DataFrame ({'A' : [1.1 ,3.3 ],'B' : [2.5 ,- 3.9 ]})
3120
+
3121
+ self ._test_op (df , operator .add )
3122
+ self ._test_op (df , operator .sub )
3123
+ self ._test_op (df , operator .mul )
3124
+ self ._test_op (df , operator .truediv )
3125
+ self ._test_op (df , operator .floordiv )
3126
+ self ._test_op (df , operator .pow )
3127
+
3128
+ self ._test_op (df , lambda x , y : y + x )
3129
+ self ._test_op (df , lambda x , y : y - x )
3130
+ self ._test_op (df , lambda x , y : y * x )
3131
+ self ._test_op (df , lambda x , y : y / x )
3132
+ self ._test_op (df , lambda x , y : y ** x )
3133
+
3134
+ self ._test_op (df , lambda x , y : x + y )
3135
+ self ._test_op (df , lambda x , y : x - y )
3136
+ self ._test_op (df , lambda x , y : x * y )
3137
+ self ._test_op (df , lambda x , y : x / y )
3138
+ self ._test_op (df , lambda x , y : x ** y )
3139
+
3140
+ @staticmethod
3141
+ def _test_op (df , op ):
3142
+ result = op (df , 1 )
3143
+
3144
+ if not df .columns .is_unique :
3145
+ raise ValueError ("Only unique columns supported by this test" )
3146
+
3147
+ for col in result .columns :
3148
+ assert_series_equal (result [col ], op (df [col ], 1 ))
3149
+
3117
3150
def test_bool_flex_frame (self ):
3118
3151
data = np .random .randn (5 , 3 )
3119
3152
other_data = np .random .randn (5 , 3 )
0 commit comments