summaryrefslogtreecommitdiff
path: root/numpy/lib/nanfunctions.py
diff options
context:
space:
mode:
authorMatti Picus <matti.picus@gmail.com>2019-12-03 12:11:37 +0200
committerGitHub <noreply@github.com>2019-12-03 12:11:37 +0200
commitb03fab8dad4a165e25739f2081e3936b522554ac (patch)
tree201fe669886ee0733d2c4e6a4d5535499bbdfa3d /numpy/lib/nanfunctions.py
parentfc860a2b279d5c370e2b332995b33528ebd97deb (diff)
parent2b51aa217bb7577f6c43c26f1156d9fc29536f96 (diff)
downloadnumpy-b03fab8dad4a165e25739f2081e3936b522554ac.tar.gz
Merge pull request #15023 from qwhelan/nan_perf
MAINT: 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