Skip to content

Commit b6af2c7

Browse files
committed
fix nonzero
1 parent 8346518 commit b6af2c7

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/pint_array/__init__.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -405,7 +405,6 @@ def func(x, /, *args, func_str=func_str, **kwargs):
405405
"argsort",
406406
"argmin",
407407
"argmax",
408-
"nonzero",
409408
):
410409

411410
def func(x, /, *args, func_str=func_str, **kwargs):
@@ -417,6 +416,14 @@ def func(x, /, *args, func_str=func_str, **kwargs):
417416

418417
setattr(mod, func_str, func)
419418

419+
def nonzero(x, /):
420+
x = asarray(x)
421+
magnitude = xp.asarray(x.magnitude, copy=True)
422+
res = xp.nonzero(magnitude)
423+
return tuple(ArrayUnitQuantity(magnitude_i, None) for magnitude_i in res)
424+
425+
mod.nonzero = nonzero
426+
420427
def searchsorted(x1, x2, /, *, side="left", sorter=None):
421428
if sorter is not None:
422429
x1 = take(x1, sorter)

0 commit comments

Comments
 (0)