@@ -2810,11 +2810,28 @@ def _arith_op(left, right):
2810
2810
return func (left , right )
2811
2811
2812
2812
if this ._is_mixed_type or other ._is_mixed_type :
2813
- # XXX no good for duplicate columns
2814
- # but cannot outer join in align if dups anyways?
2815
- result = {}
2816
- for col in this :
2817
- result [col ] = _arith_op (this [col ].values , other [col ].values )
2813
+
2814
+ # unique
2815
+ if this .columns .is_unique :
2816
+
2817
+ def f (col ):
2818
+ r = _arith_op (this [col ].values , other [col ].values )
2819
+ return self ._constructor_sliced (r ,index = new_index ,dtype = r .dtype )
2820
+
2821
+ result = dict ([ (col , f (col )) for col in this ])
2822
+
2823
+ # non-unique
2824
+ else :
2825
+
2826
+ def f (i ):
2827
+ r = _arith_op (this .iloc [:,i ].values , other .iloc [:,i ].values )
2828
+ return self ._constructor_sliced (r ,index = new_index ,dtype = r .dtype )
2829
+
2830
+ result = dict ([ (i ,f (i )) for i , col in enumerate (this .columns ) ])
2831
+ result = self ._constructor (result , index = new_index , copy = False )
2832
+ result .columns = new_columns
2833
+ return result
2834
+
2818
2835
else :
2819
2836
result = _arith_op (this .values , other .values )
2820
2837
@@ -2890,10 +2907,12 @@ def _compare(a, b):
2890
2907
# non-unique
2891
2908
else :
2892
2909
def _compare (a , b ):
2893
- return [ func (a .iloc [:,i ], b .iloc [:,i ]) for i , col in enumerate (a .columns )]
2910
+ return dict ([( i , func (a .iloc [:,i ], b .iloc [:,i ])) for i , col in enumerate (a .columns )])
2894
2911
new_data = expressions .evaluate (_compare , str_rep , self , other )
2895
- return self ._constructor (data = new_data , index = self .columns ,
2896
- columns = self .index , copy = False ).T
2912
+ result = self ._constructor (data = new_data , index = self .index ,
2913
+ copy = False )
2914
+ result .columns = self .columns
2915
+ return result
2897
2916
2898
2917
def _compare_frame (self , other , func , str_rep ):
2899
2918
if not self ._indexed_same (other ):
0 commit comments