code: def test_nifti_maps_masker_with_nans_and_infs():
      """Apply a NiftiMapsMasker containing NaNs and infs.
  
      The masker should replace those NaNs and infs with zeros,
      without raising a warning.
      """
      length = 3
      n_regions = 8
      fmri_img, mask_img = data_gen.generate_random_img(
          (13, 11, 12, length),
          affine=np.eye(4),
      )
      maps_img, _ = data_gen.generate_maps(
          (13, 11, 12),
          n_regions,
          affine=np.eye(4),
      )
  
      # Add NaNs and infs to atlas
      maps_data = get_data(maps_img).astype(np.float32)
      mask_data = get_data(mask_img).astype(np.float32)
      maps_data = maps_data * mask_data[..., None]
  
      # Choose a good voxel from the first label
      vox_idx = np.where(maps_data[..., 0] > 0)
      i1, j1, k1 = vox_idx[0][0], vox_idx[1][0], vox_idx[2][0]
      i2, j2, k2 = vox_idx[0][1], vox_idx[1][1], vox_idx[2][1]
  
      maps_data[:, :, :, 0] = np.nan
      maps_data[i2, j2, k2, 0] = np.inf
      maps_data[i1, j1, k1, 0] = 1
  
      maps_img = nibabel.Nifti1Image(maps_data, np.eye(4))
  
      # No warning, because maps_img is run through clean_img
      # *before* safe_get_data.
      masker = NiftiMapsMasker(maps_img, mask_img=mask_img)
  
      sig = masker.fit_transform(fmri_img)
  
      assert sig.shape == (length, n_regions)
      assert np.all(np.isfinite(sig))
  
file_path: nilearn/nilearn/maskers/tests/test_nifti_maps_masker.py
imports: import warnings
  import nibabel
  import numpy
  import pytest
  from nilearn._utils import data_gen, testing
  from nilearn._utils.exceptions import DimensionError
  from nilearn.image import get_data
  from nilearn.maskers import NiftiMapsMasker
label_desc: Use image node_id 3 for calling a global function with example usage: test_nifti_maps_masker_with_nans_and_infs() without return types