# Buggy code
def _nanpercentile1d(arr1d, q, overwrite_input=False, interpolation="linear"):
    """
    Private function for rank 1 arrays. Compute percentile ignoring NaNs.
    See nanpercentile for parameter usage

    """
    c = np.isnan(arr1d)
    s = np.where(c)[0]
    if s.size == arr1d.size:
        warnings.warn("All-NaN slice encountered", RuntimeWarning)
        return np.nan
    elif s.size == 0:
        return np.percentile(
            arr1d, q, overwrite_input=overwrite_input, interpolation=interpolation
        )
    else:
        if overwrite_input:
            x = arr1d
        else:
            x = arr1d.copy()
        # select non-nans at end of array
        enonan = arr1d[-s.size :][~c[-s.size :]]
        # fill nans in beginning of array with non-nans of end
        x[s[: enonan.size]] = enonan
        # slice nans away
        return np.percentile(
            x[: -s.size], q, overwrite_input=True, interpolation=interpolation
        )


# 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 _nanpercentile1d(arr1d, q, overwrite_input=False, interpolation="linear"):
    """
    Private function for rank 1 arrays. Compute percentile ignoring NaNs.
    See nanpercentile for parameter usage

    """
    c = np.isnan(arr1d)
    s = np.where(c)[0]
    if s.size == arr1d.size:
        warnings.warn("All-NaN slice encountered", RuntimeWarning)
        if q.ndim == 0:
            return np.nan
        else:
            return np.nan * np.ones((len(q),))
    elif s.size == 0:
        return np.percentile(
            arr1d, q, overwrite_input=overwrite_input, interpolation=interpolation
        )
    else:
        if overwrite_input:
            x = arr1d
        else:
            x = arr1d.copy()
        # select non-nans at end of array
        enonan = arr1d[-s.size :][~c[-s.size :]]
        # fill nans in beginning of array with non-nans of end
        x[s[: enonan.size]] = enonan
        # slice nans away
        return np.percentile(
            x[: -s.size], q, overwrite_input=True, interpolation=interpolation
        )