Repository: nilearn/nilearn

Issue:
Failure in pre-release dependencies CI job
I'm looking into this failure https://github.com/nilearn/nilearn/actions/runs/5186381231/jobs/9347413782
There have been pre-releases for numpy (1.25.0rc1) and scipy (1.11.0rc1) since last week which is around the time this failure seems to have started


Discussion:
The first failing test `test_resampling_nan` was passing by accident. The warning context uses a regular expression `r"(\bnan\b|invalid value)"` that just happens to match the following warning 
`DeprecationWarning('Passing 'np.nan' to mean no clipping in np.clip has always been unreliable, and is now deprecated. In future, this will always return nan,...'` 
which is unrelated to what is being tested. This warning is probably removed in the new pre-release and therefore there are no warnings being raised and the test fails now. This is because when the resampling function is called it does one of 2 things when resampling is needed: cropping or calling `_resample_one_img`. The latter if called would raise the right warning but it seems in this test cropping is enough and so the warning is not raised. 

My question is should this warning be raised in both cases or should the test be changed to correctly raise the warning? I'm not sure it is relevant for the cropping case.

The warning message in question is:
            "NaNs or infinite values are present in the data "
            "passed to resample. This is a bad thing as they "
            "make resampling ill-defined and much slower."

Resolving patch:
diff --git a/nilearn/image/resampling.py b/nilearn/image/resampling.py
--- a/nilearn/image/resampling.py
+++ b/nilearn/image/resampling.py
@@ -686,8 +686,8 @@ def resample_img(
         # preventing ringing artefact
         # We need to add zero as a value considered for clipping, as it
         # appears in padding images.
-        vmin = min(data.min(), 0)
-        vmax = max(data.max(), 0)
+        vmin = min(np.nanmin(data), 0)
+        vmax = max(np.nanmax(data), 0)
         resampled_data.clip(vmin, vmax, out=resampled_data)
 
     return new_img_like(img, resampled_data, target_affine)
diff --git a/nilearn/maskers/nifti_maps_masker.py b/nilearn/maskers/nifti_maps_masker.py
--- a/nilearn/maskers/nifti_maps_masker.py
+++ b/nilearn/maskers/nifti_maps_masker.py
@@ -228,10 +228,17 @@ def generate_report(self, displayed_maps=10):
         """
         from nilearn.reporting.html_report import generate_report
 
-        if (
-            displayed_maps != "all"
-            and not isinstance(displayed_maps, (list, np.ndarray, int))
-        ):
+        incorrect_type = not isinstance(
+            displayed_maps, (list, np.ndarray, int, str)
+        )
+        incorrect_string = (
+            isinstance(displayed_maps, str) and displayed_maps != "all"
+        )
+        not_integer = (
+            not isinstance(displayed_maps, str)
+            and np.array(displayed_maps).dtype != int
+        )
+        if incorrect_type or incorrect_string or not_integer:
             raise TypeError(
                 "Parameter ``displayed_maps`` of "
                 "``generate_report()`` should be either 'all' or "


Test patch:
diff --git a/nilearn/image/tests/test_resampling.py b/nilearn/image/tests/test_resampling.py
--- a/nilearn/image/tests/test_resampling.py
+++ b/nilearn/image/tests/test_resampling.py
@@ -586,8 +586,7 @@ def test_resampling_nan(affine, core_shape):
 
     # check 3x3 transformation matrix
     target_affine = np.eye(3)[axis_permutation]
-    with pytest.warns(Warning, match=r"(\bnan\b|invalid value)"):
-        resampled_img = resample_img(source_img, target_affine=target_affine)
+    resampled_img = resample_img(source_img, target_affine=target_affine)
 
     resampled_data = get_data(resampled_img)
     if full_data.ndim == 4: