Skip to content

Commit

Permalink
[FIX] Fix tests failing due to deprecations in pre-release dependenci…
Browse files Browse the repository at this point in the history
…es (#3746)

* Fix test in test_html_report

* Fix other test in test_html_report

* Remove raise warning since already tested

* Fix clipping

* Clarify if statement

* Improve if statement
  • Loading branch information
ymzayek committed Jun 9, 2023
1 parent db5a727 commit 2d3f10c
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 8 deletions.
4 changes: 2 additions & 2 deletions nilearn/image/resampling.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 1 addition & 2 deletions nilearn/image/tests/test_resampling.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
15 changes: 11 additions & 4 deletions nilearn/maskers/nifti_maps_masker.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 "
Expand Down

0 comments on commit 2d3f10c

Please sign in to comment.