@@ -280,9 +280,8 @@ def dispatch_to_series(left, right, func, axis=None):
280
280
bm = left ._mgr .operate_blockwise (right ._mgr , array_op )
281
281
return type (left )(bm )
282
282
283
- elif isinstance (right , ABCSeries ) and axis == "columns" :
284
- # We only get here if called via _combine_series_frame,
285
- # in which case we specifically want to operate row-by-row
283
+ elif isinstance (right , ABCSeries ) and axis == 1 :
284
+ # axis=1 means we want to operate row-by-row
286
285
assert right .index .equals (left .columns )
287
286
288
287
if right .dtype == "timedelta64[ns]" :
@@ -292,6 +291,8 @@ def dispatch_to_series(left, right, func, axis=None):
292
291
right = np .asarray (right )
293
292
else :
294
293
right = right ._values
294
+ # maybe_align_as_frame ensures we do not have an ndarray here
295
+ assert not isinstance (right , np .ndarray )
295
296
296
297
arrays = [array_op (l , r ) for l , r in zip (left ._iter_column_arrays (), right )]
297
298
@@ -440,35 +441,6 @@ def flex_wrapper(self, other, level=None, fill_value=None, axis=0):
440
441
# DataFrame
441
442
442
443
443
- def _combine_series_frame (left , right , func , axis : int ):
444
- """
445
- Apply binary operator `func` to self, other using alignment and fill
446
- conventions determined by the axis argument.
447
-
448
- Parameters
449
- ----------
450
- left : DataFrame
451
- right : Series
452
- func : binary operator
453
- axis : {0, 1}
454
-
455
- Returns
456
- -------
457
- result : DataFrame or Dict[int, Series[]]
458
- """
459
- # We assume that self.align(other, ...) has already been called
460
-
461
- rvalues = right ._values
462
- assert not isinstance (rvalues , np .ndarray ) # handled by align_series_as_frame
463
-
464
- if axis == 0 :
465
- new_data = dispatch_to_series (left , right , func )
466
- else :
467
- new_data = dispatch_to_series (left , right , func , axis = "columns" )
468
-
469
- return new_data
470
-
471
-
472
444
def _align_method_FRAME (
473
445
left , right , axis , flex : Optional [bool ] = False , level : Level = None
474
446
):
@@ -671,7 +643,7 @@ def f(self, other, axis=default_axis, level=None, fill_value=None):
671
643
672
644
elif isinstance (other , ABCSeries ):
673
645
axis = self ._get_axis_number (axis ) if axis is not None else 1
674
- new_data = _combine_series_frame (self , other , op , axis = axis )
646
+ new_data = dispatch_to_series (self , other , op , axis = axis )
675
647
else :
676
648
# in this case we always have `np.ndim(other) == 0`
677
649
if fill_value is not None :
@@ -707,7 +679,7 @@ def f(self, other, axis=default_axis, level=None):
707
679
708
680
elif isinstance (other , ABCSeries ):
709
681
axis = self ._get_axis_number (axis ) if axis is not None else 1
710
- new_data = _combine_series_frame (self , other , op , axis = axis )
682
+ new_data = dispatch_to_series (self , other , op , axis = axis )
711
683
else :
712
684
# in this case we always have `np.ndim(other) == 0`
713
685
new_data = dispatch_to_series (self , other , op )
@@ -730,7 +702,7 @@ def f(self, other):
730
702
self , other , axis = None , level = None , flex = False
731
703
)
732
704
733
- axis = "columns" # only relevant for Series other case
705
+ axis = 1 # only relevant for Series other case
734
706
# See GH#4537 for discussion of scalar op behavior
735
707
new_data = dispatch_to_series (self , other , op , axis = axis )
736
708
return self ._construct_result (new_data )
0 commit comments