@@ -1077,7 +1077,7 @@ def fill_binop(left, right, fill_value):
10771077 return left , right
10781078
10791079
1080- def mask_cmp_op (x , y , op , allowed_types ):
1080+ def mask_cmp_op (x , y , op ):
10811081 """
10821082 Apply the function `op` to only non-null points in x and y.
10831083
@@ -1086,16 +1086,14 @@ def mask_cmp_op(x, y, op, allowed_types):
10861086 x : array-like
10871087 y : array-like
10881088 op : binary operation
1089- allowed_types : class or tuple of classes
10901089
10911090 Returns
10921091 -------
10931092 result : ndarray[bool]
10941093 """
1095- # TODO: Can we make the allowed_types arg unnecessary?
10961094 xrav = x .ravel ()
10971095 result = np .empty (x .size , dtype = bool )
1098- if isinstance (y , allowed_types ):
1096+ if isinstance (y , ( np . ndarray , ABCSeries ) ):
10991097 yrav = y .ravel ()
11001098 mask = notna (xrav ) & notna (yrav )
11011099 result [mask ] = op (np .array (list (xrav [mask ])),
@@ -1633,39 +1631,38 @@ def _arith_method_SERIES(cls, op, special):
16331631 if op in [divmod , rdivmod ] else _construct_result )
16341632
16351633 def na_op (x , y ):
1636- import pandas .core .computation .expressions as expressions
1637- try :
1638- result = expressions .evaluate (op , str_rep , x , y , ** eval_kwargs )
1639- except TypeError :
1640- result = masked_arith_op (x , y , op )
1641-
1642- result = missing .fill_zeros (result , x , y , op_name , fill_zeros )
1643- return result
1644-
1645- def safe_na_op (lvalues , rvalues ):
16461634 """
1647- return the result of evaluating na_op on the passed in values
1635+ Return the result of evaluating op on the passed in values.
16481636
1649- try coercion to object type if the native types are not compatible
1637+ If native types are not compatible, try coersion to object dtype.
16501638
16511639 Parameters
16521640 ----------
1653- lvalues : array-like
1654- rvalues : array-like
1641+ x : array-like
1642+ y : array-like or scalar
1643+
1644+ Returns
1645+ -------
1646+ array-like
16551647
16561648 Raises
16571649 ------
1658- TypeError: invalid operation
1650+ TypeError : invalid operation
16591651 """
1652+ import pandas .core .computation .expressions as expressions
16601653 try :
1661- with np .errstate (all = 'ignore' ):
1662- return na_op (lvalues , rvalues )
1663- except Exception :
1664- if is_object_dtype (lvalues ):
1665- return libalgos .arrmap_object (lvalues ,
1666- lambda x : op (x , rvalues ))
1654+ result = expressions .evaluate (op , str_rep , x , y , ** eval_kwargs )
1655+ except TypeError :
1656+ result = masked_arith_op (x , y , op )
1657+ except Exception : # TODO: more specific?
1658+ if is_object_dtype (x ):
1659+ return libalgos .arrmap_object (x ,
1660+ lambda val : op (val , y ))
16671661 raise
16681662
1663+ result = missing .fill_zeros (result , x , y , op_name , fill_zeros )
1664+ return result
1665+
16691666 def wrapper (left , right ):
16701667 if isinstance (right , ABCDataFrame ):
16711668 return NotImplemented
@@ -1713,7 +1710,8 @@ def wrapper(left, right):
17131710 if isinstance (rvalues , ABCSeries ):
17141711 rvalues = rvalues .values
17151712
1716- result = safe_na_op (lvalues , rvalues )
1713+ with np .errstate (all = 'ignore' ):
1714+ result = na_op (lvalues , rvalues )
17171715 return construct_result (left , result ,
17181716 index = left .index , name = res_name , dtype = None )
17191717
@@ -2136,7 +2134,6 @@ def na_op(x, y):
21362134 result = masked_arith_op (x , y , op )
21372135
21382136 result = missing .fill_zeros (result , x , y , op_name , fill_zeros )
2139-
21402137 return result
21412138
21422139 if op_name in _op_descriptions :
@@ -2183,7 +2180,7 @@ def na_op(x, y):
21832180 with np .errstate (invalid = 'ignore' ):
21842181 result = op (x , y )
21852182 except TypeError :
2186- result = mask_cmp_op (x , y , op , ( np . ndarray , ABCSeries ) )
2183+ result = mask_cmp_op (x , y , op )
21872184 return result
21882185
21892186 doc = _flex_comp_doc_FRAME .format (op_name = op_name ,
0 commit comments