@@ -584,33 +584,23 @@ def flex_wrapper(self, other, level=None, fill_value=None, axis=0):
584
584
# DataFrame
585
585
586
586
587
- def _combine_series_frame (self , other , func , fill_value = None , axis = None , level = None ):
587
+ def _combine_series_frame (left , right , func , axis : int ):
588
588
"""
589
589
Apply binary operator `func` to self, other using alignment and fill
590
- conventions determined by the fill_value, axis, and level kwargs .
590
+ conventions determined by the axis argument .
591
591
592
592
Parameters
593
593
----------
594
- self : DataFrame
595
- other : Series
594
+ left : DataFrame
595
+ right : Series
596
596
func : binary operator
597
- fill_value : object, default None
598
- axis : {0, 1, 'columns', 'index', None}, default None
599
- level : int or None, default None
597
+ axis : {0, 1}
600
598
601
599
Returns
602
600
-------
603
601
result : DataFrame
604
602
"""
605
- if fill_value is not None :
606
- raise NotImplementedError (f"fill_value { fill_value } not supported." )
607
-
608
- if axis is None :
609
- # default axis is columns
610
- axis = 1
611
-
612
- axis = self ._get_axis_number (axis )
613
- left , right = self .align (other , join = "outer" , axis = axis , level = level , copy = False )
603
+ # We assume that self.align(other, ...) has already been called
614
604
if axis == 0 :
615
605
new_data = left ._combine_match_index (right , func )
616
606
else :
@@ -707,9 +697,15 @@ def f(self, other, axis=default_axis, level=None, fill_value=None):
707
697
# so do not want the masked op.
708
698
pass_op = op if axis in [0 , "columns" , None ] else na_op
709
699
pass_op = pass_op if not is_logical else op
710
- return _combine_series_frame (
711
- self , other , pass_op , fill_value = fill_value , axis = axis , level = level
700
+
701
+ if fill_value is not None :
702
+ raise NotImplementedError (f"fill_value { fill_value } not supported." )
703
+
704
+ axis = self ._get_axis_number (axis ) if axis is not None else 1
705
+ self , other = self .align (
706
+ other , join = "outer" , axis = axis , level = level , copy = False
712
707
)
708
+ return _combine_series_frame (self , other , pass_op , axis = axis )
713
709
else :
714
710
# in this case we always have `np.ndim(other) == 0`
715
711
if fill_value is not None :
@@ -745,9 +741,11 @@ def f(self, other, axis=default_axis, level=None):
745
741
return self ._construct_result (new_data )
746
742
747
743
elif isinstance (other , ABCSeries ):
748
- return _combine_series_frame (
749
- self , other , op , fill_value = None , axis = axis , level = level
744
+ axis = self ._get_axis_number (axis ) if axis is not None else 1
745
+ self , other = self .align (
746
+ other , join = "outer" , axis = axis , level = level , copy = False
750
747
)
748
+ return _combine_series_frame (self , other , op , axis = axis )
751
749
else :
752
750
# in this case we always have `np.ndim(other) == 0`
753
751
new_data = dispatch_to_series (self , other , op )
@@ -774,18 +772,21 @@ def f(self, other):
774
772
"Can only compare identically-labeled DataFrame objects"
775
773
)
776
774
new_data = dispatch_to_series (self , other , op , str_rep )
777
- return self ._construct_result (new_data )
778
775
779
776
elif isinstance (other , ABCSeries ):
780
- return _combine_series_frame (
781
- self , other , op , fill_value = None , axis = None , level = None
777
+ # axis=1 is default for DataFrame-with-Series op
778
+ self , other = self .align (
779
+ other , join = "outer" , axis = 1 , level = None , copy = False
782
780
)
781
+ new_data = dispatch_to_series (self , other , op , axis = "columns" )
782
+
783
783
else :
784
784
785
785
# straight boolean comparisons we want to allow all columns
786
786
# (regardless of dtype to pass thru) See #4537 for discussion.
787
787
new_data = dispatch_to_series (self , other , op )
788
- return self ._construct_result (new_data )
788
+
789
+ return self ._construct_result (new_data )
789
790
790
791
f .__name__ = op_name
791
792
0 commit comments