ValueError: cannot convert float NaN to integer in compute_epi_mask

Hi there, I got a problem while executing the module compute_epi_mask from nilearn.masking.

Whenever I issue:
mask = compute_epi_mask(maskPath)
where the maskPath is the string of path to my Nifti image to be extracted.

And I got the following message:

File "/home/jsl/Documents/", line 17, in 
mask = compute_epi_mask(epi_img = maskPath, ensure_finite = True)

File "/usr/lib/python3.7/site-packages/nilearn/", line 264, in compute_epi_mask
  smooth=(1 if opening else False))

File "/usr/lib/python3.7/site-packages/sklearn/externals/joblib/", line 342, in _call_
  return self.func(*args, **kwargs)

File "/usr/lib/python3.7/site-packages/nilearn/image/", line 408, in _compute_mean
  mean_data[nan_mask] = np.nan

ValueError: cannot convert float NaN to integer`

Is this my bad on syntax usage?
Sorry, since I’m new to Python, so I could’ve make some very basic mistakes.

I’m currently on Manjaro Linux 18.0.3, using Spyder 3 as IDE, where those dependencies are installed via python-pip in Manjaro official repository.

Great thanks!

P.S: Sorry but I can’t offer my Nifti file due to some privacy issues, but there shouldn’t be any NaN issues once I add ensure_Finite parameter.

the syntax you used is correct. From the error message it seems to be an issue with the image from which you compute the mask; is it possible to upload it? thanks!

From the error message, I can guess that the problem is that the image is integer values. It might be that, in some situations, our code fails with integer inputs. This could be an actual bug on our side.

If you cannot upload the image, can you e.g. perturb it with random noise or create one that triggers the bug ? Otherwise, it’ll be hard to ensure we’ve identified the bug properly.

Sorry guys, I was working on my DS homework until few days ago.
But still, I can’t upload the image since these images are not mine.
However, I knew new stuff these days while working on the image:

  1. It is a mask to mark the rate of interest on each brain image block.
  2. It is an image with integer, true.

BTW, how can I perturb it with random noise or create one that triggers the bug?
Sorry, I’m still an undergraduate newb.
Thank you very much!