Skip to content

extend-select and additional ruff rules #587

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 14 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions doc/sphinxext/autosummary_generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -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*.*?')
Expand Down
6 changes: 4 additions & 2 deletions doc/users/plots/hrf_different.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
7 changes: 5 additions & 2 deletions doc/users/plots/neuronal_block.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion examples/ds105/ds105_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
3 changes: 2 additions & 1 deletion examples/fiac/fiac_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
14 changes: 7 additions & 7 deletions examples/formula/multi_session_contrast.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,21 +25,21 @@
# 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

# 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
Expand Down
2 changes: 1 addition & 1 deletion examples/labs/need_data/one_sample_t_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}")
4 changes: 0 additions & 4 deletions lib/lapack_lite/remake/make_lite.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion nipy/algorithms/clustering/tests/test_clustering.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion nipy/algorithms/diagnostics/tests/test_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
2 changes: 1 addition & 1 deletion nipy/algorithms/graph/tests/test_forest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
6 changes: 3 additions & 3 deletions nipy/algorithms/graph/tests/test_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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()
Expand All @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion nipy/algorithms/registration/scripting.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

timefuncs = st.timefuncs.SLICETIME_FUNCTIONS

__all__ = ["space_time_realign", "aff2euler"]
__all__ = ["aff2euler", "space_time_realign"]


def aff2euler(affine):
Expand Down
14 changes: 7 additions & 7 deletions nipy/algorithms/statistics/models/tests/test_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
5 changes: 3 additions & 2 deletions nipy/algorithms/statistics/rft.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
3 changes: 2 additions & 1 deletion nipy/algorithms/statistics/tests/test_intrinsic_volumes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)


Expand Down
47 changes: 28 additions & 19 deletions nipy/algorithms/statistics/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,20 +196,22 @@
(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]]
Expand Down Expand Up @@ -384,13 +386,17 @@
ec = 0

for t in decompose3d(shape, dim=4):
ec -= 1; ts += 1
ec -= 1
ts += 1

Check warning on line 390 in nipy/algorithms/statistics/utils.py

View check run for this annotation

Codecov / codecov/patch

nipy/algorithms/statistics/utils.py#L389-L390

Added lines #L389 - L390 were not covered by tests
for f in decompose3d(shape, dim=3):
ec += 1; fs += 1
ec += 1
fs += 1

Check warning on line 393 in nipy/algorithms/statistics/utils.py

View check run for this annotation

Codecov / codecov/patch

nipy/algorithms/statistics/utils.py#L392-L393

Added lines #L392 - L393 were not covered by tests
for e in decompose3d(shape, dim=2):
ec -= 1; es += 1
ec -= 1
es += 1

Check warning on line 396 in nipy/algorithms/statistics/utils.py

View check run for this annotation

Codecov / codecov/patch

nipy/algorithms/statistics/utils.py#L395-L396

Added lines #L395 - L396 were not covered by tests
for v in decompose3d(shape, dim=1):
ec += 1; vs += 1
ec += 1
vs += 1

Check warning on line 399 in nipy/algorithms/statistics/utils.py

View check run for this annotation

Codecov / codecov/patch

nipy/algorithms/statistics/utils.py#L398-L399

Added lines #L398 - L399 were not covered by tests
return ts, fs, es, vs, ec

# Tell testing framework not to run this as a test
Expand All @@ -405,11 +411,14 @@
ec = 0

for f in decompose2d(shape, dim=3):
ec += 1; fs += 1
ec += 1
fs += 1

Check warning on line 415 in nipy/algorithms/statistics/utils.py

View check run for this annotation

Codecov / codecov/patch

nipy/algorithms/statistics/utils.py#L414-L415

Added lines #L414 - L415 were not covered by tests
for e in decompose2d(shape, dim=2):
ec -= 1; es += 1
ec -= 1
es += 1

Check warning on line 418 in nipy/algorithms/statistics/utils.py

View check run for this annotation

Codecov / codecov/patch

nipy/algorithms/statistics/utils.py#L417-L418

Added lines #L417 - L418 were not covered by tests
for v in decompose2d(shape, dim=1):
ec += 1; vs += 1
ec += 1
vs += 1

Check warning on line 421 in nipy/algorithms/statistics/utils.py

View check run for this annotation

Codecov / codecov/patch

nipy/algorithms/statistics/utils.py#L420-L421

Added lines #L420 - L421 were not covered by tests
return fs, es, vs, ec

# Tell testing framework not to run this as a test
Expand Down
4 changes: 2 additions & 2 deletions nipy/algorithms/utils/tests/test_fast_distance.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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)
4 changes: 3 additions & 1 deletion nipy/algorithms/utils/tests/test_matrices.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion nipy/core/image/tests/test_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions nipy/core/image/tests/test_image_spaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 5 additions & 2 deletions nipy/core/reference/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,8 @@

from . import coordinate_map, coordinate_system, slices

__all__ = ["coordinate_system", "coordinate_map",
"slices"]
__all__ = [
"coordinate_map",
"coordinate_system",
"slices",
]
8 changes: 6 additions & 2 deletions nipy/core/reference/tests/test_array_coords.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Loading
Loading