code: def test_nifti_labels_masker_with_nans_and_infs_in_mask():
      """Apply a NiftiLabelsMasker with a mask containing NaNs and infs.
  
      The masker should replace those NaNs and infs with zeros,
      while raising a warning.
      """
      length = 3
      n_regions = 9
      fmri_img, mask_img = data_gen.generate_random_img(
          (13, 11, 12, length),
          affine=np.eye(4),
      )
      labels_img = data_gen.generate_labeled_regions(
          (13, 11, 12),
          affine=np.eye(4),
          n_regions=n_regions,
      )
      # Introduce nans with data type float
      # See issue: https://github.com/nilearn/nilearn/issues/2580
      mask_data = get_data(mask_img).astype(np.float32)
      mask_data[:, :, 7] = np.nan
      mask_data[:, :, 4] = np.inf
      mask_img = nibabel.Nifti1Image(mask_data, np.eye(4))
  
      masker = NiftiLabelsMasker(labels_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))
  
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 NiftiLabelsMasker, NiftiMasker
label_desc: Use image node_id 4 for calling a global function with example usage: test_nifti_labels_masker_with_nans_and_infs_in_mask() without return types