Repository: nilearn/nilearn
Pull request #5274: [MAINT] remove dead code
Author: login: Remi-Gau
Created: 2025-03-25T10:15:07Z | Merged: 2025-03-25T14:21:37Z

- closes none
- remove dead code flagged by vulture
- move one function used only in testing


Diff:
diff --git a/nilearn/glm/tests/test_first_level.py b/nilearn/glm/tests/test_first_level.py
index 25059cb21d5..0caa08454e6 100644
--- a/nilearn/glm/tests/test_first_level.py
+++ b/nilearn/glm/tests/test_first_level.py
@@ -51,9 +51,6 @@
 from nilearn.surface import SurfaceImage
 from nilearn.surface._testing import assert_polymesh_equal
 
-BASEDIR = Path(__file__).resolve().parent
-FUNCFILE = BASEDIR / "functional.nii.gz"
-
 
 @pytest.mark.parametrize(
     "estimator, check, name",
diff --git a/nilearn/glm/tests/test_second_level.py b/nilearn/glm/tests/test_second_level.py
index 975440d177b..29eeda2a477 100644
--- a/nilearn/glm/tests/test_second_level.py
+++ b/nilearn/glm/tests/test_second_level.py
@@ -63,10 +63,6 @@ def test_check_estimator_invalid(estimator, check, name):  # noqa: ARG001
     check(estimator)
 
 
-# This directory path
-BASEDIR = Path(__file__).resolve().parent
-FUNCFILE = BASEDIR / "functional.nii.gz"
-
 N_PERM = 5
 SHAPE = (*_shape_3d_default(), 1)
 
diff --git a/nilearn/image/image.py b/nilearn/image/image.py
index 522cb29f70e..f921b812bc4 100644
--- a/nilearn/image/image.py
+++ b/nilearn/image/image.py
@@ -439,57 +439,6 @@ def crop_img(
     return (cropped_im, tuple(slices)) if return_offset else cropped_im
 
 
-def _pad_array(array, pad_sizes):
-    """Pad an array with zeros.
-
-    Pads an array with zeros as specified in `pad_sizes`.
-
-    Parameters
-    ----------
-    array : :class:`numpy.ndarray`
-        Array to pad.
-
-    pad_sizes : :obj:`list`
-        Padding quantity specified as
-        *[x1minpad, x1maxpad, x2minpad,x2maxpad, x3minpad, ...]*.
-
-    Returns
-    -------
-    :class:`numpy.ndarray`
-        Padded array.
-
-    Raises
-    ------
-    ValueError
-        Inconsistent min/max padding quantities.
-
-    """
-    if len(pad_sizes) % 2 != 0:
-        raise ValueError(
-            "Please specify as many max paddings as min"
-            f" paddings. You have specified {len(pad_sizes)} arguments"
-        )
-
-    all_paddings = np.zeros([array.ndim, 2], dtype=np.int64)
-    all_paddings[: len(pad_sizes) // 2] = np.array(pad_sizes).reshape(-1, 2)
-
-    lower_paddings, upper_paddings = all_paddings.T
-    new_shape = np.array(array.shape) + upper_paddings + lower_paddings
-
-    padded = np.zeros(new_shape, dtype=array.dtype)
-    source_slices = [
-        slice(max(-lp, 0), min(s + up, s))
-        for lp, up, s in zip(lower_paddings, upper_paddings, array.shape)
-    ]
-    target_slices = [
-        slice(max(lp, 0), min(s - up, s))
-        for lp, up, s in zip(lower_paddings, upper_paddings, new_shape)
-    ]
-
-    padded[tuple(target_slices)] = array[tuple(source_slices)].copy()
-    return padded
-
-
 def compute_mean(imgs, target_affine=None, target_shape=None, smooth=False):
     """Compute the mean of the images over time or the 4th dimension.
 
diff --git a/nilearn/image/tests/_testing.py b/nilearn/image/tests/_testing.py
index b5a3970b3fd..56b876cf93c 100644
--- a/nilearn/image/tests/_testing.py
+++ b/nilearn/image/tests/_testing.py
@@ -26,3 +26,54 @@ def match_headers_keys(source, target, except_keys):
             )
         else:
             assert target.header[key] == source.header[key]
+
+
+def pad_array(array, pad_sizes):
+    """Pad an array with zeros.
+
+    Pads an array with zeros as specified in `pad_sizes`.
+
+    Parameters
+    ----------
+    array : :class:`numpy.ndarray`
+        Array to pad.
+
+    pad_sizes : :obj:`list`
+        Padding quantity specified as
+        *[x1minpad, x1maxpad, x2minpad,x2maxpad, x3minpad, ...]*.
+
+    Returns
+    -------
+    :class:`numpy.ndarray`
+        Padded array.
+
+    Raises
+    ------
+    ValueError
+        Inconsistent min/max padding quantities.
+
+    """
+    if len(pad_sizes) % 2 != 0:
+        raise ValueError(
+            "Please specify as many max paddings as min"
+            f" paddings. You have specified {len(pad_sizes)} arguments"
+        )
+
+    all_paddings = np.zeros([array.ndim, 2], dtype=np.int64)
+    all_paddings[: len(pad_sizes) // 2] = np.array(pad_sizes).reshape(-1, 2)
+
+    lower_paddings, upper_paddings = all_paddings.T
+    new_shape = np.array(array.shape) + upper_paddings + lower_paddings
+
+    padded = np.zeros(new_shape, dtype=array.dtype)
+    source_slices = [
+        slice(max(-lp, 0), min(s + up, s))
+        for lp, up, s in zip(lower_paddings, upper_paddings, array.shape)
+    ]
+    target_slices = [
+        slice(max(lp, 0), min(s - up, s))
+        for lp, up, s in zip(lower_paddings, upper_paddings, new_shape)
+    ]
+
+    padded[tuple(target_slices)] = array[tuple(source_slices)].copy()
+    return padded
diff --git a/nilearn/image/tests/test_resampling.py b/nilearn/image/tests/test_resampling.py
index b3b445cd125..59fa3e2b8dd 100644
--- a/nilearn/image/tests/test_resampling.py
+++ b/nilearn/image/tests/test_resampling.py
@@ -22,7 +22,7 @@
 from nilearn._utils import testing
 from nilearn._utils.exceptions import DimensionError
 from nilearn.image import get_data
-from nilearn.image.image import _pad_array, crop_img
+from nilearn.image.image import crop_img
 from nilearn.image.resampling import (
     BoundingBoxError,
     coord_transform,
@@ -33,7 +33,7 @@
     resample_img,
     resample_to_img,
 )
-from nilearn.image.tests._testing import match_headers_keys
+from nilearn.image.tests._testing import match_headers_keys, pad_array
 
 ANGLES_TO_TEST = (0, np.pi, np.pi / 2.0, np.pi / 4.0, np.pi / 3.0)
 
@@ -717,7 +717,7 @@ def test_resampling_result_axis_permutation(
         .T.ravel()
         .astype(int)
     )
-    expected_data = _pad_array(
+    expected_data = pad_array(
         full_data.transpose(axis_permutation), list(offset_cropping)
     )
     assert_array_almost_equal(resampled_data, expected_data)
@@ -820,7 +820,7 @@ def test_crop(affine_eye):
     # Testing that padding of arrays and cropping of images work symmetrically
     shape = (4, 6, 2)
     data = np.ones(shape)
-    padded = _pad_array(data, [3, 2, 4, 4, 5, 7])
+    padded = pad_array(data, [3, 2, 4, 4, 5, 7])
     padd_nii = Nifti1Image(padded, affine_eye)
 
     cropped = crop_img(padd_nii, pad=False, copy_header=True)
diff --git a/nilearn/plotting/find_cuts.py b/nilearn/plotting/find_cuts.py
index 117fd4ab6be..4c4188e6a00 100644
--- a/nilearn/plotting/find_cuts.py
+++ b/nilearn/plotting/find_cuts.py
@@ -12,9 +12,9 @@
 from nilearn._utils.niimg import safe_get_data
 
 # Local imports
-from nilearn.image import get_data, iter_img, new_img_like, reorder_img
+from nilearn.image import get_data, iter_img, reorder_img
 from nilearn.image.image import smooth_array
-from nilearn.image.resampling import coord_transform, get_mask_bounds
+from nilearn.image.resampling import coord_transform
 from nilearn.plotting._utils import check_threshold_not_negative
 
 ###############################################################################
@@ -179,34 +179,6 @@ def find_xyz_cut_coords(img, mask_img=None, activation_threshold=None):
     ).tolist()
 
 
-def _get_auto_mask_bounds(img):
-    """Compute the bounds of the data with an automatically computed mask."""
-    data = safe_get_data(img)
-    affine = img.affine
-    if hasattr(data, "mask"):
-        # Masked array
-        mask = np.logical_not(data.mask)
-    else:
-        # The mask will be anything that is fairly different
-        # from the values in the corners
-        edge_value = float(
-            data[0, 0, 0]
-            + data[0, -1, 0]
-            + data[-1, 0, 0]
-            + data[0, 0, -1]
-            + data[-1, -1, 0]
-            + data[-1, 0, -1]
-            + data[0, -1, -1]
-            + data[-1, -1, -1]
-        )
-        edge_value /= 6
-        mask = np.abs(data - edge_value) > 0.005 * np.ptp(data)
-    xmin, xmax, ymin, ymax, zmin, zmax = get_mask_bounds(
-        new_img_like(img, mask, affine)
-    )
-    return (xmin, xmax), (ymin, ymax), (zmin, zmax)
-
-
 def _transform_cut_coords(cut_coords, direction, affine):
     """Transform cut_coords back in image space.
 
diff --git a/nilearn/reporting/glm_reporter.py b/nilearn/reporting/glm_reporter.py
index 25617124bc2..9c743501ec6 100644
--- a/nilearn/reporting/glm_reporter.py
+++ b/nilearn/reporting/glm_reporter.py
@@ -13,7 +13,6 @@
 import uuid
 import warnings
 from html import escape
-from pathlib import Path
 from string import Template
 
 import numpy as np
@@ -68,9 +67,6 @@
     )
 
 
-HTML_TEMPLATE_ROOT_PATH = Path(__file__).parent / "glm_reporter_templates"
-
-
 @fill_doc
 def make_glm_report(
     model,


Reviews:
user: login: hndgzkn
body: LGTM!
state: APPROVED
author_association: COLLABORATOR
submitted_at: 2025-03-25T13:12:50Z
user: login: Remi-Gau
state: COMMENTED
author_association: COLLABORATOR
submitted_at: 2025-03-25T14:05:40Z

Review comments:
diff_hunk: @@ -26,3 +26,54 @@ def match_headers_keys(source, target, except_keys):
             )
         else:
             assert target.header[key] == source.header[key]
+
+
+def pad_array(array, pad_sizes):
+    """Pad an array with zeros.
+
+    Pads an array with zeros as specified in `pad_sizes`.
+
+    Parameters
path: nilearn/image/tests/_testing.py
user: login: hndgzkn
body: Could the functions in `_testing` module be moved to `conftest` in the same directory and be returned from a fixture?
created_at: 2025-03-25T13:07:26Z
author_association: COLLABORATOR
diff_hunk: @@ -26,3 +26,54 @@ def match_headers_keys(source, target, except_keys):
             )
         else:
             assert target.header[key] == source.header[key]
+
+
+def pad_array(array, pad_sizes):
+    """Pad an array with zeros.
+
+    Pads an array with zeros as specified in `pad_sizes`.
+
+    Parameters
path: nilearn/image/tests/_testing.py
user: login: Remi-Gau
body: In general (but there are exceptions) we have been using fixtures as shortcuts to setting up data for a test: so in general they return an instance of a nifti, surface image... rather than a function to call

also in general (once again there must be exceptions in the codebase) we stick things in a _testing module when the functions are not shared with another subpackage
created_at: 2025-03-25T14:05:40Z
author_association: COLLABORATOR

PR comments:
user: login: github-actions[bot]
created_at: 2025-03-25T10:18:59Z
body: 👋 @Remi-Gau Thanks for creating a PR!

Until this PR is ready for review, you can include the [WIP] tag in its title, or leave it as a github draft.

Please make sure it is compliant with our [contributing guidelines](https://nilearn.github.io/stable/development.html#contribution-guidelines). In particular, be sure it checks the boxes listed below.
- [ ] PR has an interpretable title.
- [ ] PR links to Github issue with mention `Closes #XXXX` (see our documentation on [PR structure](https://nilearn.github.io/stable/development.html#pr-structure))
- [ ] Code is PEP8-compliant (see our documentation on [coding style](https://nilearn.github.io/stable/development.html#coding-style))
- [ ] Changelog or what's new entry in `doc/changes/latest.rst` (see our documentation on [PR structure](https://nilearn.github.io/stable/development.html#pr-structure))

For new features:
- [ ] There is at least one unit test per new function / class (see our documentation on [testing](https://nilearn.github.io/stable/development.html#tests))
- [ ] The new feature is demoed in at least one relevant example.

For bug fixes:
- [ ] There is at least one test that would fail under the original bug conditions.

We will review it as quick as possible, feel free to ping us with questions if needed.
author_association: CONTRIBUTOR
user: login: codecov[bot]
created_at: 2025-03-25T10:42:24Z
body: ## [Codecov](https://app.codecov.io/gh/nilearn/nilearn/pull/5274?dropdown=coverage&src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=nilearn) Report
Attention: Patch coverage is `88.88889%` with `2 lines` in your changes missing coverage. Please review.
> Project coverage is 96.88%. Comparing base [(`85ea10f`)](https://app.codecov.io/gh/nilearn/nilearn/commit/85ea10ff98e5e59a9ef651b47b740ecfd8a4ab2b?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=nilearn) to head [(`ab8679e`)](https://app.codecov.io/gh/nilearn/nilearn/commit/ab8679e9bf28ee00d56512ab702967bc5a16efdf?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=nilearn).
> Report is 4 commits behind head on main.

| [Files with missing lines](https://app.codecov.io/gh/nilearn/nilearn/pull/5274?dropdown=coverage&src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=nilearn) | Patch % | Lines |
|---|---|---|
| [nilearn/image/tests/\_testing.py](https://app.codecov.io/gh/nilearn/nilearn/pull/5274?src=pr&el=tree&filepath=nilearn%2Fimage%2Ftests%2F_testing.py&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=nilearn#diff-bmlsZWFybi9pbWFnZS90ZXN0cy9fdGVzdGluZy5weQ==) | 83.33% | [1 Missing and 1 partial :warning: ](https://app.codecov.io/gh/nilearn/nilearn/pull/5274?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=nilearn) |

<details><summary>Additional details and impacted files</summary>


```diff
@@            Coverage Diff             @@
##             main    #5274      +/-   ##
==========================================
+ Coverage   96.67%   96.88%   +0.20%     
==========================================
  Files         270      270              
  Lines       37931    37915      -16     
  Branches     3756     3755       -1     
==========================================
+ Hits        36671    36735      +64     
+ Misses        693      635      -58     
+ Partials      567      545      -22     
```

| [Flag](https://app.codecov.io/gh/nilearn/nilearn/pull/5274/flags?src=pr&el=flags&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=nilearn) | Coverage Δ | |
|---|---|---|
| [macos-latest_3.10_plotting](https://app.codecov.io/gh/nilearn/nilearn/pull/5274/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=nilearn) | `95.57% <88.88%> (?)` | |
| [macos-latest_3.11_plotting](https://app.codecov.io/gh/nilearn/nilearn/pull/5274/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=nilearn) | `95.57% <88.88%> (+0.02%)` | :arrow_up: |
| [macos-latest_3.12_plotting](https://app.codecov.io/gh/nilearn/nilearn/pull/5274/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=nilearn) | `95.57% <88.88%> (+0.02%)` | :arrow_up: |
| [macos-latest_3.13_plotting](https://app.codecov.io/gh/nilearn/nilearn/pull/5274/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=nilearn) | `95.57% <88.88%> (+0.02%)` | :arrow_up: |
| [macos-latest_3.9_min](https://app.codecov.io/gh/nilearn/nilearn/pull/5274/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=nilearn) | `77.58% <77.77%> (?)` | |
| [macos-latest_3.9_plot_min](https://app.codecov.io/gh/nilearn/nilearn/pull/5274/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=nilearn) | `95.35% <88.88%> (+0.02%)` | :arrow_up: |
| [macos-latest_3.9_plotting](https://app.codecov.io/gh/nilearn/nilearn/pull/5274/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=nilearn) | `95.57% <88.88%> (?)` | |
| [ubuntu-latest_3.10_plotting](https://app.codecov.io/gh/nilearn/nilearn/pull/5274/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=nilearn) | `95.59% <88.88%> (?)` | |
| [ubuntu-latest_3.11_plotting](https://app.codecov.io/gh/nilearn/nilearn/pull/5274/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=nilearn) | `95.59% <88.88%> (?)` | |
| [ubuntu-latest_3.12_plotting](https://app.codecov.io/gh/nilearn/nilearn/pull/5274/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=nilearn) | `95.59% <88.88%> (+0.01%)` | :arrow_up: |
| [ubuntu-latest_3.13_plotting](https://app.codecov.io/gh/nilearn/nilearn/pull/5274/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=nilearn) | `95.59% <88.88%> (?)` | |
| [ubuntu-latest_3.13_pre](https://app.codecov.io/gh/nilearn/nilearn/pull/5274/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=nilearn) | `95.59% <88.88%> (?)` | |
| [ubuntu-latest_3.9_plotting](https://app.codecov.io/gh/nilearn/nilearn/pull/5274/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=nilearn) | `95.59% <88.88%> (?)` | |
| [windows-latest_3.10_plotting](https://app.codecov.io/gh/nilearn/nilearn/pull/5274/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=nilearn) | `95.57% <88.88%> (?)` | |
| [windows-latest_3.11_plotting](https://app.codecov.io/gh/nilearn/nilearn/pull/5274/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=nilearn) | `95.57% <88.88%> (+0.02%)` | :arrow_up: |
| [windows-latest_3.12_plotting](https://app.codecov.io/gh/nilearn/nilearn/pull/5274/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=nilearn) | `95.57% <88.88%> (?)` | |
| [windows-latest_3.13_plotting](https://app.codecov.io/gh/nilearn/nilearn/pull/5274/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=nilearn) | `95.57% <88.88%> (+0.02%)` | :arrow_up: |
| [windows-latest_3.9_plotting](https://app.codecov.io/gh/nilearn/nilearn/pull/5274/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=nilearn) | `95.57% <88.88%> (?)` | |

Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=nilearn#carryforward-flags-in-the-pull-request-comment) to find out more.

</details>

[:umbrella: View full report in Codecov by Sentry](https://app.codecov.io/gh/nilearn/nilearn/pull/5274?dropdown=coverage&src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=nilearn).   
:loudspeaker: Have feedback on the report? [Share it here](https://about.codecov.io/codecov-pr-comment-feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=nilearn).

<details><summary> :rocket: New features to boost your workflow: </summary>

- :snowflake: [Test Analytics](https://docs.codecov.com/docs/test-analytics): Detect flaky tests, report on failures, and find test suite problems.
- :package: [JS Bundle Analysis](https://docs.codecov.com/docs/javascript-bundle-analysis): Save yourself from yourself by tracking and limiting bundle sizes in JS merges.
</details>
author_association: NONE