From 2b51aa217bb7577f6c43c26f1156d9fc29536f96 Mon Sep 17 00:00:00 2001 From: Christopher Whelan Date: Sun, 1 Dec 2019 09:40:25 -0800 Subject: PERF: only copy input array in _replace_nan() if there are nans to replace --- numpy/lib/nanfunctions.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'numpy/lib/nanfunctions.py') 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 -- cgit v1.2.1