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

Hi!

I’m trying to use nilearn.image.clean_img as following:
denoised_nifti = image.clean_img(subject_data,
confounds=np.asarray(confounds_clean),
detrend=True,
standardize=False,
ensure_finite=True
)
I also tried passing path to subject data and path to confounds, but I keep getting the error:

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

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

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

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

File “/home/alado/anaconda3/lib/python3.8/site-packages/numpy/lib/function_base.py”, 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.
Best,

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