code: def test_nifti_maps_masker_with_nans_and_infs_in_data():
      """Apply a NiftiMapsMasker to 4D data containing NaNs and infs.
  
      The masker should replace those NaNs and infs with zeros,
      while 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 data
      fmri_data = get_data(fmri_img)
  
      fmri_data[:, 9, 9, :] = np.nan
      fmri_data[:, 5, 5, :] = np.inf
  
      fmri_img = nibabel.Nifti1Image(fmri_data, np.eye(4))
  
      masker = NiftiMapsMasker(maps_img, mask_img=mask_img)
  
      with pytest.warns(
          UserWarning, match="Non-finite values detected."
      ):
          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 5 for calling a global function with example usage: test_nifti_maps_masker_with_nans_and_infs_in_data() without return types