ValueError: array must not contain infs or NaNs while using Nilearn.image.clean_img


I’m trying to use nilearn.image.clean_img as following:
denoised_nifti = image.clean_img(subject_data,
I also tried passing path to subject data and path to confounds, but I keep getting the error:

File “/home/alado/datasets/code/”, line 145, in
denoised_nifti = image.clean_img(subject_data,

File “/home/alado/.local/lib/python3.8/site-packages/nilearn/image/”, line 1013, in clean_img
data = signal.clean(

File “/home/alado/.local/lib/python3.8/site-packages/nilearn/”, line 588, in clean
Q, R, _ = linalg.qr(confounds, mode=‘economic’, pivoting=True)

File “/home/alado/anaconda3/lib/python3.8/site-packages/scipy/linalg/”, line 126, in qr
a1 = numpy.asarray_chkfinite(a)

File “/home/alado/anaconda3/lib/python3.8/site-packages/numpy/lib/”, line 498, in asarray_chkfinite
raise ValueError(

ValueError: array must not contain infs or NaNs

I checked the confounds file and the data with np.isfinite and it contains only finite data, no nans or inf.

Do you have any idea what might be the case?

Thanks in advance :slight_smile:

The error is quite specific, so I expect that there is something special with the econfoudn file ? Is it possible to share it somewhere ? that would be helpful.

Thanks for your response and sorry for bothering. I’ve found the source of the problem