@@ -533,18 +533,13 @@ def _maybe_align_series_as_frame(frame: "DataFrame", series: "Series", axis: int
533
533
return type (frame )(rvalues , index = frame .index , columns = frame .columns )
534
534
535
535
536
- def arith_method_FRAME (cls : Type ["DataFrame" ], op , special : bool ):
537
- # This is the only function where ` special` can be either True or False
536
+ def flex_arith_method_FRAME (cls : Type ["DataFrame" ], op , special : bool ):
537
+ assert not special
538
538
op_name = _get_op_name (op , special )
539
539
default_axis = None if special else "columns"
540
540
541
541
na_op = get_array_op (op )
542
-
543
- if op_name in _op_descriptions :
544
- # i.e. include "add" but not "__add__"
545
- doc = _make_flex_doc (op_name , "dataframe" )
546
- else :
547
- doc = _arith_doc_FRAME % op_name
542
+ doc = _make_flex_doc (op_name , "dataframe" )
548
543
549
544
@Appender (doc )
550
545
def f (self , other , axis = default_axis , level = None , fill_value = None ):
@@ -561,8 +556,6 @@ def f(self, other, axis=default_axis, level=None, fill_value=None):
561
556
562
557
axis = self ._get_axis_number (axis ) if axis is not None else 1
563
558
564
- # TODO: why are we passing flex=True instead of flex=not special?
565
- # 15 tests fail if we pass flex=not special instead
566
559
self , other = align_method_FRAME (self , other , axis , flex = True , level = level )
567
560
568
561
if isinstance (other , ABCDataFrame ):
@@ -585,6 +578,29 @@ def f(self, other, axis=default_axis, level=None, fill_value=None):
585
578
return f
586
579
587
580
581
+ def arith_method_FRAME (cls : Type ["DataFrame" ], op , special : bool ):
582
+ assert special
583
+ op_name = _get_op_name (op , special )
584
+ doc = _arith_doc_FRAME % op_name
585
+
586
+ @Appender (doc )
587
+ def f (self , other ):
588
+
589
+ if _should_reindex_frame_op (self , other , op , 1 , 1 , None , None ):
590
+ return _frame_arith_method_with_reindex (self , other , op )
591
+
592
+ axis = 1 # only relevant for Series other case
593
+
594
+ self , other = align_method_FRAME (self , other , axis , flex = True , level = None )
595
+
596
+ new_data = dispatch_to_series (self , other , op , axis = axis )
597
+ return self ._construct_result (new_data )
598
+
599
+ f .__name__ = op_name
600
+
601
+ return f
602
+
603
+
588
604
def flex_comp_method_FRAME (cls : Type ["DataFrame" ], op , special : bool ):
589
605
assert not special # "special" also means "not flex"
590
606
op_name = _get_op_name (op , special )
@@ -616,7 +632,7 @@ def comp_method_FRAME(cls: Type["DataFrame"], op, special: bool):
616
632
def f (self , other ):
617
633
axis = 1 # only relevant for Series other case
618
634
619
- self , other = align_method_FRAME (self , other , axis , level = None , flex = False )
635
+ self , other = align_method_FRAME (self , other , axis , flex = False , level = None )
620
636
621
637
# See GH#4537 for discussion of scalar op behavior
622
638
new_data = dispatch_to_series (self , other , op , axis = axis )
0 commit comments