@@ -5298,12 +5298,19 @@ def _combine_frame(self, other, func, fill_value=None, level=None):
52985298 this , other = self .align (other , join = "outer" , level = level , copy = False )
52995299 new_index , new_columns = this .index , this .columns
53005300
5301- def _arith_op (left , right ):
5302- # for the mixed_type case where we iterate over columns,
5303- # _arith_op(left, right) is equivalent to
5304- # left._binop(right, func, fill_value=fill_value)
5305- left , right = ops .fill_binop (left , right , fill_value )
5306- return func (left , right )
5301+ if fill_value is None :
5302+ # since _arith_op may be called in a loop, avoid function call
5303+ # overhead if possible by doing this check once
5304+ _arith_op = func
5305+
5306+ else :
5307+
5308+ def _arith_op (left , right ):
5309+ # for the mixed_type case where we iterate over columns,
5310+ # _arith_op(left, right) is equivalent to
5311+ # left._binop(right, func, fill_value=fill_value)
5312+ left , right = ops .fill_binop (left , right , fill_value )
5313+ return func (left , right )
53075314
53085315 if ops .should_series_dispatch (this , other , func ):
53095316 # iterate over columns
@@ -5318,7 +5325,7 @@ def _arith_op(left, right):
53185325
53195326 def _combine_match_index (self , other , func , level = None ):
53205327 left , right = self .align (other , join = "outer" , axis = 0 , level = level , copy = False )
5321- assert left .index .equals (right .index )
5328+ # at this point we have ` left.index.equals(right.index)`
53225329
53235330 if left ._is_mixed_type or right ._is_mixed_type :
53245331 # operate column-wise; avoid costly object-casting in `.values`
@@ -5331,14 +5338,13 @@ def _combine_match_index(self, other, func, level=None):
53315338 new_data , index = left .index , columns = self .columns , copy = False
53325339 )
53335340
5334- def _combine_match_columns (self , other , func , level = None ):
5335- assert isinstance (other , Series )
5341+ def _combine_match_columns (self , other : Series , func , level = None ):
53365342 left , right = self .align (other , join = "outer" , axis = 1 , level = level , copy = False )
5337- assert left .columns .equals (right .index )
5343+ # at this point we have ` left.columns.equals(right.index)`
53385344 return ops .dispatch_to_series (left , right , func , axis = "columns" )
53395345
53405346 def _combine_const (self , other , func ):
5341- assert lib . is_scalar ( other ) or np .ndim (other ) == 0
5347+ # scalar other or np.ndim(other) == 0
53425348 return ops .dispatch_to_series (self , other , func )
53435349
53445350 def combine (self , other , func , fill_value = None , overwrite = True ):
0 commit comments