Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.8/site-packages/bottleneck/slow/nonreduce.py: 19%

Shortcuts on this page

r m x   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

16 statements  

1import numpy as np 

2 

3__all__ = ["replace"] 

4 

5 

6def replace(a, old, new): 

7 "Slow replace (inplace) used for unaccelerated dtypes." 

8 if type(a) is not np.ndarray: 

9 raise TypeError("`a` must be a numpy array.") 

10 if not issubclass(a.dtype.type, np.inexact): 

11 if old != old: 

12 # int arrays do not contain NaN 

13 return 

14 if int(old) != old: 

15 raise ValueError("Cannot safely cast `old` to int.") 

16 if int(new) != new: 

17 raise ValueError("Cannot safely cast `new` to int.") 

18 if old != old: 

19 mask = np.isnan(a) 

20 else: 

21 mask = a == old 

22 np.putmask(a, mask, new)