code: def test_img_data_dtype(rng, affine_eye, tmp_path):
      # Ignoring complex, binary, 128+ bit, RGBA
      nifti1_dtypes = (
          np.uint8,
          np.uint16,
          np.uint32,
          np.uint64,
          np.int8,
          np.int16,
          np.int32,
          np.float32,
          np.float64,
      )
      dtype_matches = []
      # Passing dtype or header is required when using int64
      # https://nipy.org/nibabel/changelog.html#api-changes-and-deprecations
      hdr = Nifti1Header()
      for logical_dtype in nifti1_dtypes:
          dataobj = rng.uniform(0, 255, (2, 2, 2)).astype(logical_dtype)
          for on_disk_dtype in nifti1_dtypes:
              hdr.set_data_dtype(on_disk_dtype)
              img = Nifti1Image(dataobj, affine_eye, header=hdr)
              img.to_filename(tmp_path / "test.nii")
              loaded = nb.load(tmp_path / "test.nii")
              # To verify later that sometimes these differ meaningfully
              dtype_matches.append(
                  loaded.get_data_dtype()
                  == niimg.img_data_dtype(loaded)
              )
              assert np.array(
                  loaded.dataobj
              ).dtype == niimg.img_data_dtype(loaded)
      # Verify that the distinction is worth making
      assert any(dtype_matches)
      assert not all(dtype_matches)
  
file_path: nilearn/nilearn/_utils/tests/test_niimg.py
imports: from pathlib import Path
  import joblib
  import nibabel
  import numpy
  import pytest
  from nibabel import Nifti1Header, Nifti1Image
  from nilearn._utils import load_niimg, niimg, testing
  from nilearn.image import get_data, new_img_like
label_desc: Use image node_id 4 for calling a global function with example usage: test_img_data_dtype(rng, affine_eye, tmp_path) without return types