diff options
Diffstat (limited to 'numpy')
-rw-r--r-- | numpy/lib/function_base.py | 4 | ||||
-rw-r--r-- | numpy/lib/tests/test_function_base.py | 6 |
2 files changed, 8 insertions, 2 deletions
diff --git a/numpy/lib/function_base.py b/numpy/lib/function_base.py index a5ccc1189..a16781f53 100644 --- a/numpy/lib/function_base.py +++ b/numpy/lib/function_base.py @@ -3959,7 +3959,7 @@ def percentile(a, ``i < j``. If ``g`` is the fractional part of the index surrounded by ``i`` and alpha and beta are correction constants modifying i and j. - Below, 'q' is the quantile value, 'n' is the samle size and + Below, 'q' is the quantile value, 'n' is the sample size and alpha and beta are constants. The following formula gives an interpolation "i + g" of where the quantile would be in the sorted sample. @@ -4628,7 +4628,7 @@ def _quantile( if np.any(slices_having_nans): if result.ndim == 0 and out is None: # can't write to a scalar - result = np.array(np.nan, dtype=arr.dtype) + result = arr.dtype.type(np.nan) else: result[..., slices_having_nans] = np.nan return result diff --git a/numpy/lib/tests/test_function_base.py b/numpy/lib/tests/test_function_base.py index d59f3a85d..f9854c568 100644 --- a/numpy/lib/tests/test_function_base.py +++ b/numpy/lib/tests/test_function_base.py @@ -3475,6 +3475,12 @@ class TestQuantile: quantile = np.quantile(arr, p0) assert_equal(np.sort(quantile), quantile) + def test_quantile_scalar_nan(self): + a = np.array([[10., 7., 4.], [3., 2., 1.]]) + a[0][1] = np.nan + actual = np.quantile(a, 0.5) + assert np.isscalar(actual) + assert_equal(np.quantile(a, 0.5), np.nan) class TestLerp: @hypothesis.given(t0=st.floats(allow_nan=False, allow_infinity=False, |