Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Seaborn heatmap throws "isnan" type of error after update

Tags:

python

seaborn

I've been recently dealing with heatmaps in Python, more specifically, I've been drawing with the seaborn library. Up to some point, everything worked perfectly, my snippet looked something like:

result = df.pivot(index='indexcol', columns='coltwo', values='hvalues')
ax = sns.heatmap(result, cbar=False, yticklabels=True, xticklabels=True, linewidths=.1, cmap=ListedColormap(['white', 'green', 'red']))
plt.show()

where my result is a Pandas dataframe. After I updated to 0.8.2, it started to throw something like:

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 can fix this partially, by using result.astype(int) in the heatmap call, yet the plots do not look the same.

Apart from a downgrade, what options do I have?

like image 976
sdgaw erzswer Avatar asked Oct 01 '17 16:10

sdgaw erzswer


1 Answers

Solved this with:

result.fillna(value=np.nan, inplace=True)

a row before the heatmap plot. The problem was, that the new seaborn couldn't handle None, yet numpy nan is apparently ok.

like image 105
sdgaw erzswer Avatar answered Nov 14 '22 21:11

sdgaw erzswer