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

16 statements  

« prev     ^ index     » next       coverage.py v7.2.2, created at 2023-03-23 06:06 +0000

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)