Problem view_img_on_surf() cannot convert float NaN to integer

Hey! I’ve been having some problems executing the plotting.view_img_on_surf() command of my laptop. I keep getting the same error presented here:
cannot convert float NaN to integer

Is there anything I can do?
The thing is that this error appeared after using the command with no problems multiple times.

This is the code:

view = plotting.view_img_on_surf(total,
threshold = ‘90%’,
surf_mesh = ‘fsaverage5’,
cmap = ‘jet’,
symmetric_cmap = False,
black_bg = False)

Where total is a Nifti1Image:
<nibabel.nifti1.Nifti1Image at 0x2d194cfec88>

Thank you!

You can avoid this with a mask method. Note first that in python NaN is defined as the number which is not equal to itself:

>float('nan') == float('nan')      

It might be worth avoiding use of np.NaN altogether. NaN literally means “not a number”, and it cannot be converted to an integer. In general, Python prefers raising an exception to returning NaN, so things like sqrt(-1) and log(0.0) will generally raise instead of returning NaN. However, you may get this value back from some other library. From v0.24, you actually can. Pandas introduces Nullable Integer Data Types which allows integers to coexist with NaNs. Also, even at the lastest versions of pandas if the column is object type you would have to convert into float first, something like:


NB: You have to go through numpy float first and then to nullable Int32, for some reason.