diff --git a/doc/sphinxext/autosummary_generate.py b/doc/sphinxext/autosummary_generate.py index 4fae0e55e..b16b88eab 100755 --- a/doc/sphinxext/autosummary_generate.py +++ b/doc/sphinxext/autosummary_generate.py @@ -153,8 +153,8 @@ def get_documented_in_lines(lines, module=None, filename=None): (if present) of the directive. """ - title_underline_re = re.compile("^[-=*_^#]{3,}\s*$") - autodoc_re = re.compile(".. auto(function|method|attribute|class|exception|module)::\s*([A-Za-z0-9_.]+)\s*$") + title_underline_re = re.compile(r"^[-=*_^#]{3,}\s*$") + autodoc_re = re.compile(r".. auto(function|method|attribute|class|exception|module)::\s*([A-Za-z0-9_.]+)\s*$") autosummary_re = re.compile(r'^\.\.\s+autosummary::\s*') module_re = re.compile(r'^\.\.\s+(current)?module::\s*([a-zA-Z0-9_.]+)\s*$') autosummary_item_re = re.compile(r'^\s+([_a-zA-Z][a-zA-Z0-9_.]*)\s*.*?') diff --git a/doc/users/plots/hrf_different.py b/doc/users/plots/hrf_different.py index 527d047d2..61230f2e5 100644 --- a/doc/users/plots/hrf_different.py +++ b/doc/users/plots/hrf_different.py @@ -14,8 +14,10 @@ glover = hrf.glover(T) afni = hrf.afni(T) -ta = [0,4,8,12,16]; tb = [2,6,10,14,18] -ba = 1; bb = -2 +ta = [0,4,8,12,16] +tb = [2,6,10,14,18] +ba = 1 +bb = -2 na = ba * sum(glover.subs(T, T - t) for t in ta) nb = bb * sum(afni.subs(T, T - t) for t in tb) diff --git a/doc/users/plots/neuronal_block.py b/doc/users/plots/neuronal_block.py index 367544642..d598474f2 100644 --- a/doc/users/plots/neuronal_block.py +++ b/doc/users/plots/neuronal_block.py @@ -12,8 +12,11 @@ import pylab from sympy import Piecewise, Symbol, lambdify -ta = [0,4,8,12,16]; tb = [2,6,10,14,18] -ba = Symbol('ba'); bb = Symbol('bb'); t = Symbol('t') +ta = [0,4,8,12,16] +tb = [2,6,10,14,18] +ba = Symbol('ba') +bb = Symbol('bb') +t = Symbol('t') fa = sum(Piecewise((0, (t<_t)), ((t-_t)/0.5, (t<_t+0.5)), (1, (t >= _t+0.5))) for _t in ta)*ba fb = sum(Piecewise((0, (t<_t)), ((t-_t)/0.5, (t<_t+0.5)), (1, (t >= _t+0.5))) for _t in tb)*bb N = fa+fb diff --git a/examples/ds105/ds105_example.py b/examples/ds105/ds105_example.py index 54635b933..4cdfbb777 100644 --- a/examples/ds105/ds105_example.py +++ b/examples/ds105/ds105_example.py @@ -228,7 +228,8 @@ def run_model(subj, run): # We split the contrasts into F-tests and t-tests. # XXX helper function should do this - fcons = {}; tcons = {} + fcons = {} + tcons = {} for n, v in cons.items(): v = np.squeeze(v) if v.ndim == 1: diff --git a/examples/fiac/fiac_example.py b/examples/fiac/fiac_example.py index 00e9abe96..e6263af1a 100644 --- a/examples/fiac/fiac_example.py +++ b/examples/fiac/fiac_example.py @@ -215,7 +215,8 @@ def run_model(subj, run): # We split the contrasts into F-tests and t-tests. # XXX helper function should do this - fcons = {}; tcons = {} + fcons = {} + tcons = {} for n, v in cons.items(): v = np.squeeze(v) if v.ndim == 1: diff --git a/examples/formula/multi_session_contrast.py b/examples/formula/multi_session_contrast.py index 784e9f8b0..a362c3f08 100755 --- a/examples/formula/multi_session_contrast.py +++ b/examples/formula/multi_session_contrast.py @@ -25,10 +25,10 @@ # The events utility returns a formula in terms of 't' - general time c11 = c11.subs(t, t1) # Now make it in terms of time in run 1 # Same for conditions 2 and 3 -c21 = utils.events([1, 3, 9], f=h1); c21 = c21.subs(t, t1) -c31 = utils.events([2, 4, 8], f=h1); c31 = c31.subs(t, t1) +c21 = utils.events([1, 3, 9], f=h1).subs(t, t1) +c31 = utils.events([2, 4, 8], f=h1).subs(t, t1) # Add also a Fourier basis set for drift with frequencies 0.3, 0.5, 0.7 -d1 = utils.fourier_basis([0.3, 0.5, 0.7]); d1 = d1.subs(t, t1) +d1 = utils.fourier_basis([0.3, 0.5, 0.7]).subs(t, t1) # Here's our formula for run 1 signal terms of time in run 1 (t1) f1 = Formula([c11,c21,c31]) + d1 @@ -36,10 +36,10 @@ # run 2 t2 = Term('t2') # Time within run 2 # Conditions 1 through 3 in run 2 -c12 = utils.events([3.3, 7, 10], f=h2); c12 = c12.subs(t, t2) -c22 = utils.events([1, 3.2, 9], f=h2); c22 = c22.subs(t, t2) -c32 = utils.events([2, 4.2, 8], f=h2); c32 = c32.subs(t, t2) -d2 = utils.fourier_basis([0.3, 0.5, 0.7]); d2 = d2.subs(t, t2) +c12 = utils.events([3.3, 7, 10], f=h2).subs(t, t2) +c22 = utils.events([1, 3.2, 9], f=h2).subs(t, t2) +c32 = utils.events([2, 4.2, 8], f=h2).subs(t, t2) +d2 = utils.fourier_basis([0.3, 0.5, 0.7]).subs(t, t2) # Formula for run 2 signal in terms of time in run 2 (t2) f2 = Formula([c12, c22, c32]) + d2 diff --git a/examples/labs/need_data/one_sample_t_test.py b/examples/labs/need_data/one_sample_t_test.py index ac99beea7..69b565820 100755 --- a/examples/labs/need_data/one_sample_t_test.py +++ b/examples/labs/need_data/one_sample_t_test.py @@ -82,6 +82,6 @@ vmax=vmax, threshold=3., black_bg=True) -plt.savefig(path.join(write_dir, f'one_sample_z_map.png')) +plt.savefig(path.join(write_dir, 'one_sample_z_map.png')) plt.show() print(f"Wrote all the results in directory {write_dir}") diff --git a/lib/lapack_lite/remake/make_lite.py b/lib/lapack_lite/remake/make_lite.py index caae87449..4d13e647a 100755 --- a/lib/lapack_lite/remake/make_lite.py +++ b/lib/lapack_lite/remake/make_lite.py @@ -6,10 +6,6 @@ import clapack_scrub import fortran -try: set -except NameError: - from sets import Set as set - # Arguments to pass to f2c. You'll always want -A for ANSI C prototypes # Others of interest: -a to not make variables static by default # -C to check array subscripts diff --git a/nipy/algorithms/clustering/tests/test_clustering.py b/nipy/algorithms/clustering/tests/test_clustering.py index d9a87f912..9598355a7 100644 --- a/nipy/algorithms/clustering/tests/test_clustering.py +++ b/nipy/algorithms/clustering/tests/test_clustering.py @@ -15,7 +15,7 @@ class TestClustering(TestCase): def testkmeans1(self): X = nr.randn(10, 2) A = np.concatenate([np.ones((7, 2)),np.zeros((3, 2))]) - X = X + 3 * A; + X = X + 3 * A L = np.array([0, 0, 0, 0, 0, 1, 1, 1, 1, 1]) C, L, J = kmeans(X, 2, L) self.assertLess(np.mean(L[:7]), 0.5) diff --git a/nipy/algorithms/diagnostics/tests/test_commands.py b/nipy/algorithms/diagnostics/tests/test_commands.py index 63e976b1c..1a3336779 100644 --- a/nipy/algorithms/diagnostics/tests/test_commands.py +++ b/nipy/algorithms/diagnostics/tests/test_commands.py @@ -94,7 +94,7 @@ def test_parse_fname_axes(in_tmp_path): assert slice_axis == 'j' -class Args: pass +class Args: ... def check_axes(axes, img_shape, time_axis, slice_axis): diff --git a/nipy/algorithms/graph/tests/test_forest.py b/nipy/algorithms/graph/tests/test_forest.py index e187edb78..f1be0bb65 100644 --- a/nipy/algorithms/graph/tests/test_forest.py +++ b/nipy/algorithms/graph/tests/test_forest.py @@ -74,7 +74,7 @@ def test_all_distances(): dg = f.all_distances(1) assert dg[3] == 3. -def test_depth(): +def test_depth_from_leaves(): """ test the depth_from_leaves() methods """ f = simple_forest() diff --git a/nipy/algorithms/graph/tests/test_graph.py b/nipy/algorithms/graph/tests/test_graph.py index 33f6c0022..07129215b 100644 --- a/nipy/algorithms/graph/tests/test_graph.py +++ b/nipy/algorithms/graph/tests/test_graph.py @@ -350,7 +350,7 @@ def test_voronoi(): """ a = np.array([0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6]) b = np.array([1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 0, 0, 1]) - d = np.array([1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2]); + d = np.array([1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2]) edges = np.transpose(np.vstack((a, b))) G = WeightedGraph(7, edges,d) G.symmeterize() @@ -364,7 +364,7 @@ def test_voronoi2(): """ a = np.array([0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6]) b = np.array([1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 0, 0, 1]) - d = np.array([1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2]); + d = np.array([1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2]) edges = np.vstack((a, b)).T G = WeightedGraph(7, edges,d) G.symmeterize() @@ -378,7 +378,7 @@ def test_voronoi3(): """ a = np.array([0, 1, 2, 5, 6]) b = np.array([1, 2, 3, 6, 0]) - d = np.array([1, 1, 1, 1, 1]); + d = np.array([1, 1, 1, 1, 1]) edges = np.vstack((a, b)).T G = WeightedGraph(7, edges,d) G.symmeterize() diff --git a/nipy/algorithms/registration/scripting.py b/nipy/algorithms/registration/scripting.py index 4b0cfc7cd..6ae144875 100644 --- a/nipy/algorithms/registration/scripting.py +++ b/nipy/algorithms/registration/scripting.py @@ -24,7 +24,7 @@ timefuncs = st.timefuncs.SLICETIME_FUNCTIONS -__all__ = ["space_time_realign", "aff2euler"] +__all__ = ["aff2euler", "space_time_realign"] def aff2euler(affine): diff --git a/nipy/algorithms/statistics/models/tests/test_model.py b/nipy/algorithms/statistics/models/tests/test_model.py index 4269eee50..45e1c05d2 100644 --- a/nipy/algorithms/statistics/models/tests/test_model.py +++ b/nipy/algorithms/statistics/models/tests/test_model.py @@ -82,19 +82,19 @@ def test_t_output(): assert_array_almost_equal(res.effect, exp_effect) assert_array_almost_equal(res.sd, exp_sd) res = RESULTS.Tcontrast([1,0], store=('effect',)) - assert res.t == None + assert res.t is None assert_array_almost_equal(res.effect, exp_effect) - assert res.sd == None + assert res.sd is None res = RESULTS.Tcontrast([1,0], store=('t',)) assert_array_almost_equal(res.t, exp_t) - assert res.effect == None - assert res.sd == None + assert res.effect is None + assert res.sd is None res = RESULTS.Tcontrast([1,0], store=('sd',)) - assert res.t == None - assert res.effect == None + assert res.t is None + assert res.effect is None assert_array_almost_equal(res.sd, exp_sd) res = RESULTS.Tcontrast([1,0], store=('effect', 'sd')) - assert res.t == None + assert res.t is None assert_array_almost_equal(res.effect, exp_effect) assert_array_almost_equal(res.sd, exp_sd) diff --git a/nipy/algorithms/statistics/rft.py b/nipy/algorithms/statistics/rft.py index b7a783d37..9e5f40252 100644 --- a/nipy/algorithms/statistics/rft.py +++ b/nipy/algorithms/statistics/rft.py @@ -199,7 +199,8 @@ def __setattr__(self, key, val): self.__dict__[key] = val else: raise ValueError('expecting positive float or inf') - else: np.poly1d.__setattr__(self, key, val) + else: + np.poly1d.__setattr__(self, key, val) def compatible(self, other): """ Check compatibility of degrees of freedom @@ -220,7 +221,7 @@ def compatible(self, other): False >>> """ - if self.m != other.m: + if self.m != other.m: # noqa: SIM103 #raise ValueError, 'quasi polynomials are not compatible, m disagrees' return False return True diff --git a/nipy/algorithms/statistics/tests/test_intrinsic_volumes.py b/nipy/algorithms/statistics/tests/test_intrinsic_volumes.py index d2ea35de7..60604b319 100644 --- a/nipy/algorithms/statistics/tests/test_intrinsic_volumes.py +++ b/nipy/algorithms/statistics/tests/test_intrinsic_volumes.py @@ -43,7 +43,8 @@ def randombox(shape): for j in range(len(shape)): edges[j].sort() if edges[j][0] == edges[j][1]: - edges[j][0] = 0; edges[j][1] = shape[j]/2+1 + edges[j][0] = 0 + edges[j][1] = shape[j]/2+1 return edges, box(shape, edges) diff --git a/nipy/algorithms/statistics/utils.py b/nipy/algorithms/statistics/utils.py index 96b3806ab..1937c4e5c 100644 --- a/nipy/algorithms/statistics/utils.py +++ b/nipy/algorithms/statistics/utils.py @@ -196,20 +196,22 @@ def cube_with_strides_center(center=[0,0,0], (0, 7, 5, 1), (0, 7, 4, 6), (0, 3, 1, 7)] - vertices = [] - for k in range(2): - for j in range(2): - for i in range(2): - vertices.append((center[0]+i)*strides[0] + - (center[1]+j)*strides[1] + - (center[2]+k)*strides[2]) + vertices = [ + (center[0]+i)*strides[0] + + (center[1]+j)*strides[1] + + (center[2]+k)*strides[2] + for k in range(2) + for j in range(2) + for i in range(2) + ] elif d == 2: maximal = [(0,1,3), (0,2,3)] - vertices = [] - for j in range(2): - for i in range(2): - vertices.append((center[0]+i)*strides[0] + - (center[1]+j)*strides[1]) + vertices = [ + (center[0]+i)*strides[0] + + (center[1]+j)*strides[1] + for j in range(2) + for i in range(2) + ] elif d == 1: maximal = [(0,1)] vertices = [center[0],center[0]+strides[0]] @@ -384,13 +386,17 @@ def test_EC3(shape): ec = 0 for t in decompose3d(shape, dim=4): - ec -= 1; ts += 1 + ec -= 1 + ts += 1 for f in decompose3d(shape, dim=3): - ec += 1; fs += 1 + ec += 1 + fs += 1 for e in decompose3d(shape, dim=2): - ec -= 1; es += 1 + ec -= 1 + es += 1 for v in decompose3d(shape, dim=1): - ec += 1; vs += 1 + ec += 1 + vs += 1 return ts, fs, es, vs, ec # Tell testing framework not to run this as a test @@ -405,11 +411,14 @@ def test_EC2(shape): ec = 0 for f in decompose2d(shape, dim=3): - ec += 1; fs += 1 + ec += 1 + fs += 1 for e in decompose2d(shape, dim=2): - ec -= 1; es += 1 + ec -= 1 + es += 1 for v in decompose2d(shape, dim=1): - ec += 1; vs += 1 + ec += 1 + vs += 1 return fs, es, vs, ec # Tell testing framework not to run this as a test diff --git a/nipy/algorithms/utils/tests/test_fast_distance.py b/nipy/algorithms/utils/tests/test_fast_distance.py index 7b0ccf630..8c3e7ee09 100644 --- a/nipy/algorithms/utils/tests/test_fast_distance.py +++ b/nipy/algorithms/utils/tests/test_fast_distance.py @@ -18,7 +18,7 @@ def test_euclidean_1(): ED = ed(X, Y) ref = np.zeros((nx, ny)) for i in range(nx): - ref[i] = np.sqrt(np.sum((Y - X[i])**2, 1)) + ref[i] = np.sqrt(np.sum((Y - X[i])**2, 1)) assert_almost_equal(ED, ref) @@ -31,6 +31,6 @@ def test_euclidean_2(): ED = ed(X) ref = np.zeros((nx, nx)) for i in range(nx): - ref[i] = np.sqrt(np.sum((X - X[i])**2, 1)) + ref[i] = np.sqrt(np.sum((X - X[i])**2, 1)) assert_almost_equal(ED, ref) diff --git a/nipy/algorithms/utils/tests/test_matrices.py b/nipy/algorithms/utils/tests/test_matrices.py index 2070cf38f..f1a9f2edb 100644 --- a/nipy/algorithms/utils/tests/test_matrices.py +++ b/nipy/algorithms/utils/tests/test_matrices.py @@ -12,7 +12,9 @@ def test_matrix_rank(): # Full rank matrix assert 4 == matrix_rank(np.eye(4)) - I=np.eye(4); I[-1,-1] = 0. # rank deficient matrix + # rank deficient matrix + I=np.eye(4) + I[-1,-1] = 0. assert matrix_rank(I) == 3 # All zeros - zero rank assert matrix_rank(np.zeros((4,4))) == 0 diff --git a/nipy/core/image/tests/test_image.py b/nipy/core/image/tests/test_image.py index 6f43cdcd2..e3487f8aa 100644 --- a/nipy/core/image/tests/test_image.py +++ b/nipy/core/image/tests/test_image.py @@ -210,7 +210,7 @@ def test_from_image(): assert_array_equal(img.get_fdata(), img2.get_fdata()) assert img.coordmap == img2.coordmap assert img.metadata == img2.metadata - assert not img.metadata is img2.metadata + assert img.metadata is not img2.metadata # optional inputs - data arr2 = arr + 10 new = Image.from_image(img, arr2) diff --git a/nipy/core/image/tests/test_image_spaces.py b/nipy/core/image/tests/test_image_spaces.py index 25131d334..99c6d398c 100644 --- a/nipy/core/image/tests/test_image_spaces.py +++ b/nipy/core/image/tests/test_image_spaces.py @@ -70,13 +70,13 @@ def test_image_as_xyz_image(): for tmap in (img_ro_out, img_ro_in, img_ro_both): assert not is_xyz_affable(tmap) img_r = as_xyz_image(tmap) - assert not tmap is img_r + assert tmap is not img_r assert img == img_r assert_array_equal(img.get_fdata(), img_r.get_fdata()) img_t0 = rollimg(img, 't') assert not is_xyz_affable(img_t0) img_t0_r = as_xyz_image(img_t0) - assert not img_t0 is img_t0_r + assert img_t0 is not img_t0_r assert_array_equal(img.get_fdata(), img_t0_r.get_fdata()) assert img.coordmap == img_t0_r.coordmap # Test against nibabel image diff --git a/nipy/core/reference/__init__.py b/nipy/core/reference/__init__.py index 740161650..54c4ebdbe 100644 --- a/nipy/core/reference/__init__.py +++ b/nipy/core/reference/__init__.py @@ -42,5 +42,8 @@ from . import coordinate_map, coordinate_system, slices -__all__ = ["coordinate_system", "coordinate_map", - "slices"] +__all__ = [ + "coordinate_map", + "coordinate_system", + "slices", +] diff --git a/nipy/core/reference/tests/test_array_coords.py b/nipy/core/reference/tests/test_array_coords.py index fe8a8f0a1..a5a10f8e0 100644 --- a/nipy/core/reference/tests/test_array_coords.py +++ b/nipy/core/reference/tests/test_array_coords.py @@ -25,8 +25,12 @@ def test_array_coord_map(): # lost dimension, with all zeros, except for the translation in the # now-removed dimension, encoding the position of that particular # slice - xz = 1.1; yz = 2.3; zz = 3.5 - xt = 10.0; yt = 11; zt = 12 + xz = 1.1 + yz = 2.3 + zz = 3.5 + xt = 10.0 + yt = 11 + zt = 12 aff = np.diag([xz, yz, zz, 1]) aff[:3,3] = [xt, yt, zt] shape = (2,3,4) diff --git a/nipy/core/reference/tests/test_coordinate_map.py b/nipy/core/reference/tests/test_coordinate_map.py index 0435c4651..154654f3a 100644 --- a/nipy/core/reference/tests/test_coordinate_map.py +++ b/nipy/core/reference/tests/test_coordinate_map.py @@ -383,7 +383,7 @@ def test_affine_inverse(): badcm = AffineTransform(CoordinateSystem('ij'), CoordinateSystem('x'), badaff) - assert badcm.inverse() == None + assert badcm.inverse() is None def test_affine_from_params(): @@ -1021,7 +1021,7 @@ def test_dtype_cmap_inverses(): assert res.dtype == np.float64 # preserve_dtype=True means there is no valid inverse for non integer # affine inverses, as here - assert cmap.inverse(preserve_dtype=True) == None + assert cmap.inverse(preserve_dtype=True) is None def test_subtype_equalities(): @@ -1030,12 +1030,12 @@ def test_subtype_equalities(): out_cs = CoordinateSystem('xyz') f = lambda x : x + 1 cmap = CoordinateMap(in_cs, out_cs, f) - class CM2(CoordinateMap): pass + class CM2(CoordinateMap): ... cmap2 = CM2(in_cs, out_cs, f) assert cmap == cmap2 assert cmap2 == cmap cmap = AffineTransform(in_cs, out_cs, np.eye(4)) - class AT2(AffineTransform): pass + class AT2(AffineTransform): ... cmap2 = AT2(in_cs, out_cs, np.eye(4)) assert cmap == cmap2 assert cmap2 == cmap diff --git a/nipy/core/reference/tests/test_coordinate_system.py b/nipy/core/reference/tests/test_coordinate_system.py index 66e4736a1..99b4ac400 100644 --- a/nipy/core/reference/tests/test_coordinate_system.py +++ b/nipy/core/reference/tests/test_coordinate_system.py @@ -147,7 +147,7 @@ def test_is_coordsys(): # Test coordinate system check csys = CoordinateSystem('ijk') assert is_coordsys(csys) - class C: pass + class C: ... c = C() assert not is_coordsys(c) c.coord_names = [] @@ -263,7 +263,7 @@ def test_is_coordsys_maker(): # Test coordinate system check cm = CoordSysMaker('xyz') assert is_coordsys_maker(cm) - class C: pass + class C: ... c = C() assert not is_coordsys_maker(c) c.coord_names = [] diff --git a/nipy/core/reference/tests/test_matrix_groups.py b/nipy/core/reference/tests/test_matrix_groups.py index a70fd75e5..5a20f9ae1 100644 --- a/nipy/core/reference/tests/test_matrix_groups.py +++ b/nipy/core/reference/tests/test_matrix_groups.py @@ -42,7 +42,8 @@ def test2(): detZ = np.linalg.det(Z) if detZ < 0: W = -Z - else: W = Z + else: + W = Z f = np.fabs(detZ)**(1/3.) SL_Z = MG.SLR(W/f, 'xyz') diff --git a/nipy/core/reference/tests/test_parametrized_surface.py b/nipy/core/reference/tests/test_parametrized_surface.py index 58976b2fe..40740d5a3 100644 --- a/nipy/core/reference/tests/test_parametrized_surface.py +++ b/nipy/core/reference/tests/test_parametrized_surface.py @@ -26,7 +26,9 @@ def parametric_mapping(vals): """ def implicit(vals): - x = vals[:,0]; y = vals[:,1]; z = vals[:,2] + x = vals[:,0] + y = vals[:,1] + z = vals[:,2] return x**2-y**2*z**2+z**3 surface_param = CoordinateMap(uv, xyz, parametric_mapping) diff --git a/nipy/core/reference/tests/test_spaces.py b/nipy/core/reference/tests/test_spaces.py index 15809137d..0be511eb2 100644 --- a/nipy/core/reference/tests/test_spaces.py +++ b/nipy/core/reference/tests/test_spaces.py @@ -115,7 +115,7 @@ def test_known_space(): cs = sp.to_coordsys_maker()(3) assert known_space(cs) == sp cs = CS('xyz') - assert known_space(cs) == None + assert known_space(cs) is None sp0 = XYZSpace('hijo') sp1 = XYZSpace('hija') custom_spaces = (sp0, sp1) diff --git a/nipy/io/tests/test_nifti_ref.py b/nipy/io/tests/test_nifti_ref.py index 5a9a3159e..afcbdad16 100644 --- a/nipy/io/tests/test_nifti_ref.py +++ b/nipy/io/tests/test_nifti_ref.py @@ -55,7 +55,7 @@ def test_basic_nipy2nifti(): ni_img = nipy2nifti(fimg) new_hdr = get_header(ni_img) # header copied on the way through - assert not hdr is new_hdr + assert hdr is not new_hdr # Check information preserved assert hdr['slice_duration'] == new_hdr['slice_duration'] assert_array_equal(data, ni_img.get_fdata()) diff --git a/nipy/labs/spatial_models/tests/test_bsa_io.py b/nipy/labs/spatial_models/tests/test_bsa_io.py index 62e010bf2..a8239281a 100644 --- a/nipy/labs/spatial_models/tests/test_bsa_io.py +++ b/nipy/labs/spatial_models/tests/test_bsa_io.py @@ -27,7 +27,7 @@ def test_parcel_intra_from_3d_images_list(in_tmp_path): prevalence_threshold=0, prevalence_pval=0.5, write_dir=in_tmp_path, algorithm='density', contrast_id=contrast_id) - assert landmark == None + assert landmark is None assert len(hrois) == 5 assert exists(f'density_{contrast_id}.nii') assert exists(f'prevalence_{contrast_id}.nii') diff --git a/nipy/labs/spatial_models/tests/test_parcel_io.py b/nipy/labs/spatial_models/tests/test_parcel_io.py index 47f3779b9..dbd4ab735 100644 --- a/nipy/labs/spatial_models/tests/test_parcel_io.py +++ b/nipy/labs/spatial_models/tests/test_parcel_io.py @@ -27,7 +27,7 @@ def test_mask_parcel(): def test_mask_parcel_multi_subj(in_tmp_path): """ Test that mask parcellation performs correctly """ - rng = np.random.RandomState(0); + rng = np.random.RandomState(0) n_parcels = 20 shape = (10, 10, 10) n_subjects = 5 diff --git a/nipy/labs/viz_tools/coord_tools.py b/nipy/labs/viz_tools/coord_tools.py index 5c3b2081a..7309c22a9 100644 --- a/nipy/labs/viz_tools/coord_tools.py +++ b/nipy/labs/viz_tools/coord_tools.py @@ -162,8 +162,10 @@ def _maximally_separated_subset(x, k): """ # base cases - if k < 1: raise ValueError("k = %i < 1 is senseless." % k) - if k == 1: return [x[len(x) // 2]] + if k < 1: + raise ValueError("k = %i < 1 is senseless." % k) + if k == 1: + return [x[len(x) // 2]] # would-be maximally separated subset of k (not showing the terminal nodes) msss = list(range(1, len(x) - 1)) diff --git a/nipy/labs/viz_tools/maps_3d.py b/nipy/labs/viz_tools/maps_3d.py index eb6b0aa65..5e5119ac9 100644 --- a/nipy/labs/viz_tools/maps_3d.py +++ b/nipy/labs/viz_tools/maps_3d.py @@ -358,7 +358,7 @@ def plot_map_3d(map, affine, cut_coords=None, anat=None, anat_affine=None, else: module = None - if not anat is False: + if anat is not False: plot_anat_3d(anat=anat, anat_affine=anat_affine, scale=1.05, outline_color=(.9, .9, .9), gyri_opacity=.2) diff --git a/nipy/modalities/fmri/design.py b/nipy/modalities/fmri/design.py index 484125e0f..d520bd9bc 100644 --- a/nipy/modalities/fmri/design.py +++ b/nipy/modalities/fmri/design.py @@ -422,9 +422,11 @@ def stack_designs(*pairs): contrasts = {} for p in pairs: if isinstance(p, np.ndarray): - new_X = p; new_con = {} + new_X = p + new_con = {} elif len(p) == 1: # Length one sequence - new_X = p[0]; new_con = {} + new_X = p[0] + new_con = {} else: # Length 2 sequence new_X, new_con = p X, contrasts = stack2designs(X, new_X, contrasts, new_con) diff --git a/nipy/modalities/fmri/design_matrix.py b/nipy/modalities/fmri/design_matrix.py index 66653a1df..f5407598f 100644 --- a/nipy/modalities/fmri/design_matrix.py +++ b/nipy/modalities/fmri/design_matrix.py @@ -257,7 +257,7 @@ def __init__(self, matrix, names, frametimes=None): if frametimes is not None: if frametimes.size != matrix.shape[0]: raise ValueError( - 'The number %d of frametimes is different from the' + \ + 'The number %d of frametimes is different from the ' \ 'number %d of rows' % (frametimes.size, matrix.shape[0])) self.frametimes = np.asarray(frametimes, dtype=np.float64) diff --git a/nipy/modalities/fmri/hrf.py b/nipy/modalities/fmri/hrf.py index 649a35334..d0d37db43 100644 --- a/nipy/modalities/fmri/hrf.py +++ b/nipy/modalities/fmri/hrf.py @@ -135,7 +135,9 @@ def _get_num_int(lf, dt=0.02, t=50): # Symbolic function dglover = implemented_function('dglover', dglovert) -del(_gexpr); del(_dpos); del(_dgexpr) +del(_gexpr) +del(_dpos) +del(_dgexpr) # AFNI's HRF _aexpr = sympy.Piecewise((T, T >= 0), (0, True))**8.6 * sympy.exp(-T/0.547) diff --git a/nipy/modalities/fmri/tests/test_fmri.py b/nipy/modalities/fmri/tests/test_fmri.py index 1acc41c1f..dfa0ee1c0 100644 --- a/nipy/modalities/fmri/tests/test_fmri.py +++ b/nipy/modalities/fmri/tests/test_fmri.py @@ -39,7 +39,8 @@ def test_iter(): for i, d in axis0_generator(img.get_fdata()): j += 1 assert d.shape == exp_shape - del(i); gc.collect() + del(i) + gc.collect() assert j == img_shape[1] diff --git a/nipy/modalities/fmri/tests/test_utils.py b/nipy/modalities/fmri/tests/test_utils.py index 74c7ed631..fbb68d02b 100644 --- a/nipy/modalities/fmri/tests/test_utils.py +++ b/nipy/modalities/fmri/tests/test_utils.py @@ -130,7 +130,7 @@ def test_step_function(): lam = lambdify(t, s) assert_array_equal(lam(tval), [0, 4, 4, 2, 2, 1]) # Name default - assert not re.match(r'step\d+\(t\)$', str(s)) is None + assert re.match(r'step\d+\(t\)$', str(s)) is not None # Name reloaded s = step_function([0,4,5],[4,2,1], name='goodie_goodie_yum_yum') assert str(s) == 'goodie_goodie_yum_yum(t)' @@ -147,7 +147,7 @@ def test_blocks(): assert_array_equal(lam(tval), [0, 3, 0, 5]) # Check what happens with names # Default is from step function - assert not re.match(r'step\d+\(t\)$', str(b)) is None + assert re.match(r'step\d+\(t\)$', str(b)) is not None # Can pass in another b = blocks(on_off, name='funky_chicken') assert str(b) == 'funky_chicken(t)' diff --git a/nipy/testing/tests/test_images.py b/nipy/testing/tests/test_images.py index 694e2b4d2..449abf5f4 100644 --- a/nipy/testing/tests/test_images.py +++ b/nipy/testing/tests/test_images.py @@ -14,4 +14,4 @@ def test_dims(): assert_array_equal(fimg.coordmap.affine[3, 3], 2.0) # should follow, but also make sure affine is invertible ainv = fimg.coordmap.inverse - assert not ainv is None + assert ainv is not None diff --git a/pyproject.toml b/pyproject.toml index 5240aaea4..1d444cf86 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -84,22 +84,41 @@ nipy_diagnose = 'nipy.cli.diagnose:main' line-length = 88 [tool.ruff.lint] -select = [ +extend-select = [ 'I', 'UP', 'C4', - 'E713', 'PIE', - 'PGH003', + 'PGH', 'PLR0402', - 'SIM101', - 'SIM109', - 'SIM110', - 'SIM118', - 'SIM2' + 'SIM', + 'PERF', + 'RUF' ] ignore = [ - 'UP031' + 'F401', + 'F402', + 'F403', + 'F821', + 'F841', + 'E402', + 'E712', + 'E721', + 'E722', + 'E731', + 'E741', + 'E742', + 'UP031', + 'SIM102', + 'SIM105', + 'SIM108', + 'SIM114', + 'SIM115', + 'SIM300', + 'PERF203', + 'RUF005', + 'RUF012', + 'RUF015' ] [tool.spin] diff --git a/tools/apigen.py b/tools/apigen.py index c25636c93..89f71ec3c 100644 --- a/tools/apigen.py +++ b/tools/apigen.py @@ -41,7 +41,7 @@ def __init__(self, package_skip_patterns=None, module_skip_patterns=None, ): - ''' Initialize package for parsing + r''' Initialize package for parsing Parameters ---------- @@ -312,7 +312,7 @@ def _survives_exclude(self, matchstr, match_type): return True def discover_modules(self): - ''' Return module sequence discovered from ``self.package_name`` + r''' Return module sequence discovered from ``self.package_name`` Parameters diff --git a/tools/gitwash_dumper.py b/tools/gitwash_dumper.py index 9f53cef23..2da80f4f4 100755 --- a/tools/gitwash_dumper.py +++ b/tools/gitwash_dumper.py @@ -120,8 +120,8 @@ def make_link_targets(proj_name, """ with open(known_link_fname) as link_fh: link_contents = link_fh.readlines() - have_url = not url is None - have_ml_url = not ml_url is None + have_url = url is not None + have_ml_url = ml_url is not None have_gh_url = None for line in link_contents: if not have_url: @@ -140,12 +140,12 @@ def make_link_targets(proj_name, raise RuntimeError('Need command line or known project ' 'and / or mailing list URLs') lines = [] - if not url is None: + if url is not None: lines.append(f'.. _`{proj_name}`: {url}\n') if not have_gh_url: gh_url = f'https://github.com/{user_name}/{repo_name}\n' lines.append(f'.. _`{proj_name} github`: {gh_url}\n') - if not ml_url is None: + if ml_url is not None: lines.append(f'.. _`{proj_name} mailing list`: {ml_url}\n') if len(lines) == 0: # Nothing to do @@ -216,7 +216,7 @@ def main(): out_path, cp_globs=(pjoin('gitwash', '*'),), rep_globs=('*.rst',), - renames=(('\.rst$', options.source_suffix),)) + renames=((r'\.rst$', options.source_suffix),)) make_link_targets(project_name, options.main_gh_user, options.repo_name,