code: def test_img_to_signals_labels_warnings(labeled_regions, fmri_img):
      labels_data = get_data(labeled_regions)
  
      mask_img = _create_mask_with_3_regions_from_labels_data(
          labels_data, labeled_regions.affine
      )
  
      # apply img_to_signals_labels with a masking,
      # containing only 3 regions, but
      # not keeping the masked labels
      with pytest.warns(
          UserWarning,
          match="After applying mask to the labels image, "
          "the following labels were "
          r"removed: \{3, 4, 6, 7, 8\}. "
          "Out of 9 labels, the "
          "masked labels image only contains "
          "4 labels "
          r"\(including background\).",
      ):
          labels_signals, labels_labels = img_to_signals_labels(
              imgs=fmri_img,
              labels_img=labeled_regions,
              mask_img=mask_img,
              keep_masked_labels=False,
          )
  
      # only 3 regions must be kept, others must be removed
      assert labels_signals.shape == (N_TIMEPOINTS, 3)
      assert len(labels_labels) == 3
  
      # apply img_to_signals_labels with a masking,
      # containing only 3 regions, and
      # keeping the masked labels
      # test if the warning is raised
  
      with pytest.warns(
          DeprecationWarning,
          match='Applying "mask_img" before '
          "signal extraction may result in empty region signals in "
          "the output. These are currently kept. "
          "Starting from version 0.13, the default behavior will be "
          "changed to remove them by setting "
          '"keep_masked_labels=False". '
          '"keep_masked_labels" parameter will be removed '
          "in version 0.15.",
      ):
          labels_signals, labels_labels = img_to_signals_labels(
              imgs=fmri_img,
              labels_img=labeled_regions,
              mask_img=mask_img,
              keep_masked_labels=True,
          )
  
      # all regions must be kept
      assert labels_signals.shape == (N_TIMEPOINTS, 8)
      assert len(labels_labels) == 8
  
      # test return_masked_atlas deprecation warning
      with pytest.warns(
          DeprecationWarning,
          match='After version 0.13. "img_to_signals_labels" will also return '
          'the "masked_atlas". Meanwhile "return_masked_atlas" parameter can be '
          "used to toggle this behavior. In version 0.15, "
          '"return_masked_atlas" parameter will be removed.',
      ):
          img_to_signals_labels(
              imgs=fmri_img,
              labels_img=labeled_regions,
              mask_img=mask_img,
              keep_masked_labels=False,
              return_masked_atlas=False,
          )
  
imports: import warnings
  import numpy
  import pytest
  from nibabel import Nifti1Image
  from numpy.testing import assert_almost_equal, assert_equal
  from nilearn._utils.data_gen import generate_fake_fmri, generate_labeled_regions, generate_maps, generate_timeseries
  from nilearn._utils.exceptions import DimensionError
  from nilearn._utils.testing import write_imgs_to_path
  from nilearn.conftest import _affine_eye, _shape_3d_default
  from nilearn.image import get_data, new_img_like
  from nilearn.maskers import NiftiLabelsMasker
  from nilearn.regions.signal_extraction import _check_shape_and_affine_compatibility, _trim_maps, img_to_signals_labels, img_to_signals_maps, signals_to_img_labels, signals_to_img_maps
label_desc: Use image node_id 29 for calling a global function with example usage: test_img_to_signals_labels_warnings(labeled_regions, fmri_img) without return types