# Buggy code
def _nanpercentile(
    a,
    q,
    axis=None,
    out=None,
    overwrite_input=False,
    interpolation="linear",
    keepdims=False,
):
    """
    Private function that doesn't support extended axis or keepdims.
    These methods are extended to this function using _ureduce
    See nanpercentile for parameter usage

    """
    if axis is None:
        part = a.ravel()
        result = _nanpercentile1d(part, q, overwrite_input, interpolation)
    else:
        result = np.apply_along_axis(
            _nanpercentile1d, axis, a, q, overwrite_input, interpolation
        )

    if out is not None:
        out[...] = result
    return result


# Traceback (ValueError)
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.

# Fixed code
def _nanpercentile(
    a,
    q,
    axis=None,
    out=None,
    overwrite_input=False,
    interpolation="linear",
    keepdims=False,
):
    """
    Private function that doesn't support extended axis or keepdims.
    These methods are extended to this function using _ureduce
    See nanpercentile for parameter usage

    """
    if axis is None:
        part = a.ravel()
        result = _nanpercentile1d(part, q, overwrite_input, interpolation)
    else:
        result = np.apply_along_axis(
            _nanpercentile1d, axis, a, q, overwrite_input, interpolation
        )
        # apply_along_axis fills in collapsed axis with results.
        # Move that axis to the beginning to match percentile's
        # convention.
        if q.ndim != 0:
            result = np.swapaxes(result, 0, axis)
    if out is not None:
        out[...] = result
    return result