summaryrefslogtreecommitdiff
path: root/numpy/lib/nanfunctions.py
diff options
context:
space:
mode:
authorBas van Beek <b.f.van.beek@vu.nl>2021-05-22 16:18:47 +0200
committerBas van Beek <b.f.van.beek@vu.nl>2021-05-22 16:18:47 +0200
commitae9314eff5d539122bf87800a1bc50a9f99762a8 (patch)
tree25a7f47cb3c7fd9841af12a3186ba77b6793bee0 /numpy/lib/nanfunctions.py
parent410924efc5f65d09ca1c128369099b2a4c7551b1 (diff)
downloadnumpy-ae9314eff5d539122bf87800a1bc50a9f99762a8.tar.gz
MAINT: Directly grab `nan` from the input array
Directly grab a nan-esque object from the input array, rather than constructing a new one from scratch
Diffstat (limited to 'numpy/lib/nanfunctions.py')
-rw-r--r--numpy/lib/nanfunctions.py12
1 files changed, 7 insertions, 5 deletions
diff --git a/numpy/lib/nanfunctions.py b/numpy/lib/nanfunctions.py
index 719c529c1..2c2c3435b 100644
--- a/numpy/lib/nanfunctions.py
+++ b/numpy/lib/nanfunctions.py
@@ -962,14 +962,16 @@ def _nanmedian1d(arr1d, overwrite_input=False):
Private function for rank 1 arrays. Compute the median ignoring NaNs.
See nanmedian for parameter usage
"""
- arr1d, overwrite_input = _remove_nan_1d(arr1d,
- overwrite_input=overwrite_input)
- if arr1d.size == 0:
+ arr1d_parsed, overwrite_input = _remove_nan_1d(
+ arr1d, overwrite_input=overwrite_input,
+ )
+
+ if arr1d_parsed.size == 0:
# Ensure that a nan-esque scalar of the appropiate type (and unit)
# is returned for `timedelta64` and `complexfloating`
- return np.array(np.nan).astype(arr1d.dtype, copy=False)[()]
+ return arr1d[-1]
- return np.median(arr1d, overwrite_input=overwrite_input)
+ return np.median(arr1d_parsed, overwrite_input=overwrite_input)
def _nanmedian(a, axis=None, out=None, overwrite_input=False):