You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In [3]: data = np.array([105, 100, np.nan, 10, 14, np.nan]).astype('object')
...:
...: np.nanpercentile(data, np.arange(0, 101, 10))
TypeError: ufunc 'isnan' not supported for the input types, and the inputs could not be safely coerced to any supported types according to the casting rule ''safe''
I found this while using np.percentile on a Pandas DataFrame where the underlying numpy array had an object dtype. Interestingly the Pandas quantile method (which I probably should have been using instead) handles NaNs correctly. Since that works it's possible somebody has thought about this and I will learn something new. In any case, the no warning and bad output in a large DataFrame with only couple of NaNs results in an easily overlooked mistake.
The text was updated successfully, but these errors were encountered:
I have observed some unusual behavior in the numpy percentile function when dtype is object.
This works as expected, sorting the values and giving me the percentiles:
If there are NaNs in there I get a warning, as I should:
Now I restart Python and change the dtype to object:
No warning and bad output.
I know there is the
nanpercentile
function but it rejects input of dtype object.This works as expected:
This is rejected:
I found this while using
np.percentile
on a Pandas DataFrame where the underlying numpy array had an object dtype. Interestingly the Pandasquantile
method (which I probably should have been using instead) handles NaNs correctly. Since that works it's possible somebody has thought about this and I will learn something new. In any case, the no warning and bad output in a large DataFrame with only couple of NaNs results in an easily overlooked mistake.The text was updated successfully, but these errors were encountered: