@@ -289,6 +289,7 @@ cdef inline bint is_null_period(v):
289289def _create_binary_propagating_op (name , divmod = False ):
290290
291291 def method (self , other ):
292+ print (" binop" , other, type (other))
292293 if (other is C_NA or isinstance (other, str )
293294 or isinstance (other, (numbers.Number, np.bool_, np.int64, np.int_))
294295 or isinstance (other, np.ndarray) and not other.shape):
@@ -297,6 +298,15 @@ def _create_binary_propagating_op(name, divmod=False):
297298 else :
298299 return NA
299300
301+ elif isinstance (other, np.ndarray):
302+ out = np.empty(other.shape, dtype = object )
303+ out[:] = NA
304+
305+ if divmod :
306+ return out, out.copy()
307+ else :
308+ return out
309+
300310 return NotImplemented
301311
302312 method.__name__ = name
@@ -484,6 +494,8 @@ class NAType(C_NAType):
484494 return type (other)(1 )
485495 else :
486496 return NA
497+ elif isinstance (other, np.ndarray):
498+ return np.where(other == 0 , other.dtype.type(1 ), NA)
487499
488500 return NotImplemented
489501
@@ -495,6 +507,8 @@ class NAType(C_NAType):
495507 return other
496508 else :
497509 return NA
510+ elif isinstance (other, np.ndarray):
511+ return np.where((other == 1 ) | (other == - 1 ), other, NA)
498512
499513 return NotImplemented
500514
@@ -534,18 +548,23 @@ class NAType(C_NAType):
534548
535549 def __array_ufunc__ (self , ufunc , method , *inputs , **kwargs ):
536550 types = self ._HANDLED_TYPES + (NAType,)
551+ print (' array_ufunc' , ' inputs' , inputs)
537552 for x in inputs:
538553 if not isinstance (x, types):
554+ print (' defer' , x)
539555 return NotImplemented
540556
541557 if method != " __call__" :
542558 raise ValueError (f" ufunc method '{method}' not supported for NA" )
543559 result = maybe_dispatch_ufunc_to_dunder_op(self , ufunc, method, * inputs, ** kwargs)
560+ print (" dispatch result" , result)
544561 if result is NotImplemented :
562+ # TODO: this is wrong for binary, ternary ufuncs. Should handle shape stuff.
545563 if ufunc.nout == 1 :
546564 result = NA
547565 else :
548566 result = (NA,) * ufunc.nout
567+
549568 return result
550569
551570
0 commit comments