From f91f4bcd050299c930092390b54ce9ba51fd70e0 Mon Sep 17 00:00:00 2001 From: Bas van Beek Date: Sat, 22 May 2021 15:48:23 +0200 Subject: BUG: Fixed an issue wherein `nanmedian` could return an array with the wrong dtype --- numpy/lib/nanfunctions.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'numpy/lib/nanfunctions.py') diff --git a/numpy/lib/nanfunctions.py b/numpy/lib/nanfunctions.py index a02ad779f..02ad01a98 100644 --- a/numpy/lib/nanfunctions.py +++ b/numpy/lib/nanfunctions.py @@ -965,7 +965,9 @@ def _nanmedian1d(arr1d, overwrite_input=False): arr1d, overwrite_input = _remove_nan_1d(arr1d, overwrite_input=overwrite_input) if arr1d.size == 0: - return np.nan + # 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 np.median(arr1d, overwrite_input=overwrite_input) -- cgit v1.2.1