summaryrefslogtreecommitdiff
path: root/numpy/lib/nanfunctions.py
diff options
context:
space:
mode:
authorChristopher Whelan <topherwhelan@gmail.com>2019-12-01 09:40:25 -0800
committerChristopher Whelan <topherwhelan@gmail.com>2019-12-02 19:47:18 -0800
commit2b51aa217bb7577f6c43c26f1156d9fc29536f96 (patch)
tree370a578669b5e94ca7390267aed92bc7b34c53f3 /numpy/lib/nanfunctions.py
parentb83f10ef7ee766bf30ccfa563b6cc8f7fd38a4c8 (diff)
downloadnumpy-2b51aa217bb7577f6c43c26f1156d9fc29536f96.tar.gz
PERF: only copy input array in _replace_nan() if there are nans to replace
Diffstat (limited to 'numpy/lib/nanfunctions.py')
-rw-r--r--numpy/lib/nanfunctions.py3
1 files changed, 2 insertions, 1 deletions
diff --git a/numpy/lib/nanfunctions.py b/numpy/lib/nanfunctions.py
index 457cca146..8e2a34e70 100644
--- a/numpy/lib/nanfunctions.py
+++ b/numpy/lib/nanfunctions.py
@@ -95,7 +95,7 @@ def _replace_nan(a, val):
NaNs, otherwise return None.
"""
- a = np.array(a, subok=True, copy=True)
+ a = np.asanyarray(a)
if a.dtype == np.object_:
# object arrays do not support `isnan` (gh-9009), so make a guess
@@ -106,6 +106,7 @@ def _replace_nan(a, val):
mask = None
if mask is not None:
+ a = np.array(a, subok=True, copy=True)
np.copyto(a, val, where=mask)
return a, mask