@@ -289,6 +289,7 @@ cdef inline bint is_null_period(v):
289
289
def _create_binary_propagating_op (name , divmod = False ):
290
290
291
291
def method (self , other ):
292
+ print (" binop" , other, type (other))
292
293
if (other is C_NA or isinstance (other, str )
293
294
or isinstance (other, (numbers.Number, np.bool_, np.int64, np.int_))
294
295
or isinstance (other, np.ndarray) and not other.shape):
@@ -297,6 +298,15 @@ def _create_binary_propagating_op(name, divmod=False):
297
298
else :
298
299
return NA
299
300
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
+
300
310
return NotImplemented
301
311
302
312
method.__name__ = name
@@ -484,6 +494,8 @@ class NAType(C_NAType):
484
494
return type (other)(1 )
485
495
else :
486
496
return NA
497
+ elif isinstance (other, np.ndarray):
498
+ return np.where(other == 0 , other.dtype.type(1 ), NA)
487
499
488
500
return NotImplemented
489
501
@@ -495,6 +507,8 @@ class NAType(C_NAType):
495
507
return other
496
508
else :
497
509
return NA
510
+ elif isinstance (other, np.ndarray):
511
+ return np.where((other == 1 ) | (other == - 1 ), other, NA)
498
512
499
513
return NotImplemented
500
514
@@ -534,18 +548,23 @@ class NAType(C_NAType):
534
548
535
549
def __array_ufunc__ (self , ufunc , method , *inputs , **kwargs ):
536
550
types = self ._HANDLED_TYPES + (NAType,)
551
+ print (' array_ufunc' , ' inputs' , inputs)
537
552
for x in inputs:
538
553
if not isinstance (x, types):
554
+ print (' defer' , x)
539
555
return NotImplemented
540
556
541
557
if method != " __call__" :
542
558
raise ValueError (f" ufunc method '{method}' not supported for NA" )
543
559
result = maybe_dispatch_ufunc_to_dunder_op(self , ufunc, method, * inputs, ** kwargs)
560
+ print (" dispatch result" , result)
544
561
if result is NotImplemented :
562
+ # TODO: this is wrong for binary, ternary ufuncs. Should handle shape stuff.
545
563
if ufunc.nout == 1 :
546
564
result = NA
547
565
else :
548
566
result = (NA,) * ufunc.nout
567
+
549
568
return result
550
569
551
570
0 commit comments