Closed
Description
nanpercentile
crashes when an slice is filled with nans
and multiple percentiles are requested:
In [9]: np.nanpercentile([[np.nan, np.nan], [np.nan, 2]], [50, 100], axis=0)
/usr/lib/python3.4/site-packages/numpy/lib/nanfunctions.py:914: RuntimeWarning: All-NaN slice encountered
warnings.warn("All-NaN slice encountered", RuntimeWarning)
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-9-f425a58093df> in <module>()
----> 1 np.nanpercentile([[np.nan, np.nan], [np.nan, 2]], [50, 100], axis=0)
/usr/lib/python3.4/site-packages/numpy/lib/nanfunctions.py in nanpercentile(a, q, axis, out, overwrite_input, interpolation, keepdims)
873 r, k = _ureduce(a, func=_nanpercentile, q=q, axis=axis, out=out,
874 overwrite_input=overwrite_input,
--> 875 interpolation=interpolation)
876 if keepdims:
877 if q.ndim == 0:
/usr/lib/python3.4/site-packages/numpy/lib/function_base.py in _ureduce(a, func, **kwargs)
2801 keepdim = [1] * a.ndim
2802
-> 2803 r = func(a, **kwargs)
2804 return r, keepdim
2805
/usr/lib/python3.4/site-packages/numpy/lib/nanfunctions.py in _nanpercentile(a, q, axis, out, overwrite_input, interpolation, keepdims)
896 else:
897 result = np.apply_along_axis(_nanpercentile1d, axis, a, q,
--> 898 overwrite_input, interpolation)
899
900 if out is not None:
/usr/lib/python3.4/site-packages/numpy/lib/shape_base.py in apply_along_axis(func1d, axis, arr, *args, **kwargs)
106 i.put(indlist, ind)
107 res = func1d(arr[tuple(i.tolist())], *args, **kwargs)
--> 108 outarr[tuple(ind)] = res
109 k += 1
110 return outarr
ValueError: setting an array element with a sequence.
It also sometimes returns an incorrectly sized array (compare with np.percentile
):
In [12]: np.nanpercentile([[np.nan, np.nan]], [50, 100], axis=0)
/usr/lib/python3.4/site-packages/numpy/lib/nanfunctions.py:914: RuntimeWarning: All-NaN slice encountered
warnings.warn("All-NaN slice encountered", RuntimeWarning)
Out[12]: array([ nan, nan])
In [13]: np.percentile([[1, 2]], [50, 100], axis=0)
Out[13]:
array([[ 1., 2.],
[ 1., 2.]])
Finally, the function also seems not mentioned at all in the official docs (except in the release notes).