From b84d9bcef8e080d5151dadf10ed5e5b67a88a22d Mon Sep 17 00:00:00 2001 From: Dimitri Papadopoulos <3234522+DimitriPapadopoulos@users.noreply.github.com> Date: Fri, 4 Oct 2024 22:51:40 +0200 Subject: [PATCH 1/3] Apply ruff/flake8-simplify rule SIM103 SIM103 Return the (negated) condition directly --- nipy/algorithms/registration/optimizer.py | 5 +---- nipy/algorithms/statistics/models/regression.py | 8 ++------ 2 files changed, 3 insertions(+), 10 deletions(-) diff --git a/nipy/algorithms/registration/optimizer.py b/nipy/algorithms/registration/optimizer.py index d52d3b49b..3ba3edfc1 100644 --- a/nipy/algorithms/registration/optimizer.py +++ b/nipy/algorithms/registration/optimizer.py @@ -46,7 +46,4 @@ def configure_optimizer(optimizer, fprime=None, fhess=None, **kwargs): def use_derivatives(optimizer): - if optimizer in ('simplex', 'powell'): - return False - else: - return True + return optimizer not in ('simplex', 'powell') diff --git a/nipy/algorithms/statistics/models/regression.py b/nipy/algorithms/statistics/models/regression.py index 6f72b4113..660babb33 100644 --- a/nipy/algorithms/statistics/models/regression.py +++ b/nipy/algorithms/statistics/models/regression.py @@ -264,9 +264,7 @@ def has_intercept(self): o = np.ones(self.design.shape[0]) obeta = np.dot(self.calc_beta, o) ohat = np.dot(self.wdesign, obeta) - if np.allclose(ohat, o): - return True - return False + return np.allclose(ohat, o) @cached_property def rank(self): @@ -872,6 +870,4 @@ def isestimable(C, D): if C.shape[1] != D.shape[1]: raise ValueError('Contrast should have %d columns' % D.shape[1]) new = np.vstack([C, D]) - if matrix_rank(new) != matrix_rank(D): - return False - return True + return matrix_rank(new) == matrix_rank(D) From d6946b6602f3889875fdda5fe2cdb6206a63811b Mon Sep 17 00:00:00 2001 From: Dimitri Papadopoulos <3234522+DimitriPapadopoulos@users.noreply.github.com> Date: Fri, 4 Oct 2024 22:52:44 +0200 Subject: [PATCH 2/3] Apply ruff/flake8-simplify rule SIM401 SIM401 Use `get()` instead of an `if` block --- nipy/io/tests/test_nibcompat.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nipy/io/tests/test_nibcompat.py b/nipy/io/tests/test_nibcompat.py index f37618eb7..66e5b9867 100644 --- a/nipy/io/tests/test_nibcompat.py +++ b/nipy/io/tests/test_nibcompat.py @@ -42,7 +42,7 @@ def test_unscaled_data(in_tmp_path): header = get_header(img_back) dao = get_dataobj(img_back) slope = header['scl_slope'] - inter = (0. if 'scl_inter' not in header else header['scl_inter']) + inter = (header.get('scl_inter', 0.0)) if np.isnan(slope): slope, inter = dao.slope, dao.inter data_back = np.array(dao) From 21c58c841d208cfe0bc709f930b87d856a1e9055 Mon Sep 17 00:00:00 2001 From: Dimitri Papadopoulos <3234522+DimitriPapadopoulos@users.noreply.github.com> Date: Fri, 4 Oct 2024 22:53:36 +0200 Subject: [PATCH 3/3] Apply ruff/flake8-simplify rule SIM910 SIM910 Use `get(...)` instead of `get(..., None)` --- nipy/io/nifti_ref.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nipy/io/nifti_ref.py b/nipy/io/nifti_ref.py index 3bc32d976..ff72b1e58 100644 --- a/nipy/io/nifti_ref.py +++ b/nipy/io/nifti_ref.py @@ -580,7 +580,7 @@ def nifti2nipy(ni_img): if ndim == 3: return Image(data, cmap3, {'header': hdr}) space_units, time_like_units = hdr.get_xyzt_units() - units_info = TIME_LIKE_UNITS.get(time_like_units, None) + units_info = TIME_LIKE_UNITS.get(time_like_units) n_ns = ndim - 3 ns_zooms = list(hdr.get_zooms()[3:]) ns_trans = [0] * n_ns