Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TypeError: ufunc 'isfinite' not supported for the input types, and the inputs could not be safely coerced to any supported types

After running this line im getting the following error: TypeError: ufunc 'isfinite' not supported for the input types, and the inputs could not be safely coerced to any supported types according to the casting rule ''safe''

df[~(  (pd.np.isclose(df.Sizes.round(3), df.Volumes))  & (df['color'] == 'Blue')   )] 

how can I fix it?

like image 778
Paxsivir Avatar asked Oct 27 '22 11:10

Paxsivir


1 Answers

In [152]: df=pd.DataFrame(np.arange(12.).reshape(4,3), columns=['one','two','three'])                        
In [153]: df.three[:] = ['a',np.nan,4,3.2]                                                                   
In [154]: df                                                                                                 
Out[154]: 
   one   two three
0  0.0   1.0     a
1  3.0   4.0   nan
2  6.0   7.0     4
3  9.0  10.0   3.2
In [155]: pd.np.isclose(df.one.round(3), df.two)                                                             
Out[155]: array([False, False, False, False])
In [156]: pd.np.isclose(df.one.round(3), df.three)                                                           
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-156-d99a19b1d9b5> in <module>
----> 1 pd.np.isclose(df.one.round(3), df.three)

/usr/local/lib/python3.6/dist-packages/numpy/core/numeric.py in isclose(a, b, rtol, atol, equal_nan)
   2520 
   2521     xfin = isfinite(x)
-> 2522     yfin = isfinite(y)
   2523     if all(xfin) and all(yfin):
   2524         return within_tol(x, y, atol, rtol)

TypeError: ufunc 'isfinite' not supported for the input types, and the inputs could not be safely coerced to any supported types according to the casting rule ''safe''

The test on two float32 columns works, but raises this error when one column is object dtype with non-numeric values.

like image 153
hpaulj Avatar answered Nov 20 '22 13:11

hpaulj