Skip to content

Commit ee5b25e

Browse files
authored
Merge pull request #578 from DimitriPapadopoulos/C4
Apply ruff/flake8-comprehensions preview rules (C4)
2 parents 3ef4a6f + c2be7cf commit ee5b25e

File tree

10 files changed

+16
-16
lines changed

10 files changed

+16
-16
lines changed

doc/users/plots/hrf_different.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616

1717
ta = [0,4,8,12,16]; tb = [2,6,10,14,18]
1818
ba = 1; bb = -2
19-
na = ba * sum([glover.subs(T, T - t) for t in ta])
20-
nb = bb * sum([afni.subs(T, T - t) for t in tb])
19+
na = ba * sum(glover.subs(T, T - t) for t in ta)
20+
nb = bb * sum(afni.subs(T, T - t) for t in tb)
2121

2222
nav = lambdify_t(na)
2323
nbv = lambdify_t(nb)

doc/users/plots/neuronal_block.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414

1515
ta = [0,4,8,12,16]; tb = [2,6,10,14,18]
1616
ba = Symbol('ba'); bb = Symbol('bb'); t = Symbol('t')
17-
fa = sum([Piecewise((0, (t<_t)), ((t-_t)/0.5, (t<_t+0.5)), (1, (t >= _t+0.5))) for _t in ta])*ba
18-
fb = sum([Piecewise((0, (t<_t)), ((t-_t)/0.5, (t<_t+0.5)), (1, (t >= _t+0.5))) for _t in tb])*bb
17+
fa = sum(Piecewise((0, (t<_t)), ((t-_t)/0.5, (t<_t+0.5)), (1, (t >= _t+0.5))) for _t in ta)*ba
18+
fb = sum(Piecewise((0, (t<_t)), ((t-_t)/0.5, (t<_t+0.5)), (1, (t >= _t+0.5))) for _t in tb)*bb
1919
N = fa+fb
2020

2121
Nn = N.subs(ba,1)

doc/users/plots/neuronal_event.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
ba = Symbol('ba')
1515
bb = Symbol('bb')
1616
t = Symbol('t')
17-
fa = sum([Heaviside(t - _t) for _t in ta]) * ba
18-
fb = sum([Heaviside(t - _t) for _t in tb]) * bb
17+
fa = sum(Heaviside(t - _t) for _t in ta) * ba
18+
fb = sum(Heaviside(t - _t) for _t in tb) * bb
1919
N = fa + fb
2020

2121
Nn = N.subs(ba, 1)

nipy/algorithms/registration/tests/test_histogram_registration.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ def test_set_fov():
203203
R = HistogramRegistration(I, J)
204204
R.set_fov(npoints=np.prod(I.shape))
205205
assert R._from_data.shape == I.shape
206-
half_shape = tuple([I.shape[i] / 2 for i in range(3)])
206+
half_shape = tuple(I.shape[i] / 2 for i in range(3))
207207
R.set_fov(spacing=(2, 2, 2))
208208
assert R._from_data.shape == half_shape
209209
R.set_fov(corner=half_shape)

nipy/algorithms/statistics/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ def cube_with_strides_center(center=[0,0,0],
218218
for m in maximal:
219219
nm = [vertices[j] for j in m]
220220
mm.append(nm)
221-
maximal = [tuple([vertices[j] for j in m]) for m in maximal]
221+
maximal = [tuple(vertices[j] for j in m) for m in maximal]
222222
return complex(maximal)
223223

224224

nipy/core/reference/array_coords.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ def from_shape(coordmap, shape):
183183
are 'array' coordinates.
184184
185185
"""
186-
slices = tuple([slice(0,s,1) for s in shape])
186+
slices = tuple(slice(0,s,1) for s in shape)
187187
return Grid(coordmap)[slices]
188188

189189
def __repr__(self):

nipy/core/reference/slices.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,4 +222,4 @@ def bounding_box(coordmap, shape):
222222
((2.0, 31.0), (4.0, 121.0), (6.0, 101.0))
223223
"""
224224
e = ArrayCoordMap.from_shape(coordmap, shape)
225-
return tuple([(r.min(), r.max()) for r in e.transposed_values])
225+
return tuple((r.min(), r.max()) for r in e.transposed_values)

nipy/io/tests/test_save.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ def test_save3(in_tmp_path):
8585
data = tmp.get_fdata().copy()
8686
img2 = api.Image(data, tmp.coordmap, tmp.metadata)
8787
del tmp
88-
assert tuple([img.shape[l] for l in [3,2,1,0]]) == img2.shape
88+
assert tuple(img.shape[l] for l in [3,2,1,0]) == img2.shape
8989
a = np.transpose(img.get_fdata(), [3,2,1,0])
9090
assert not np.allclose(img.affine, img2.affine)
9191
assert np.allclose(a, img2.get_fdata())

nipy/labs/tests/test_statistical_mapping.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,17 +53,17 @@ def test_6():
5353
img = make_surrogate_data()
5454
clusters, info = cluster_stats(img, img, height_th=.05,
5555
height_control='fdr', cluster_th=0, nulls={})
56-
print(len(clusters), sum([c['size'] for c in clusters]))
56+
print(len(clusters), sum(c['size'] for c in clusters))
5757
assert len(clusters)==4
5858

5959
def test7():
6060
img = make_surrogate_data()
6161
clusters, info = cluster_stats(img, img, height_th=3., height_control='None', cluster_th=0, nulls={})
62-
nstv = sum([c['size'] for c in clusters])
62+
nstv = sum(c['size'] for c in clusters)
6363
assert nstv==36
6464

6565
def test_8():
6666
img = make_surrogate_data()
6767
clusters, info = cluster_stats(img, img, height_th=.001, height_control='fpr', cluster_th=0, nulls={})
68-
nstv = sum([c['size'] for c in clusters])
68+
nstv = sum(c['size'] for c in clusters)
6969
assert nstv==36

nipy/modalities/fmri/tests/test_glm.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,8 +166,8 @@ def test_glm_ar():
166166
mulm, n, p, q = ar1_glm()
167167
assert len(mulm.labels_) == n
168168
assert len(mulm.results_) > 1
169-
tmp = sum([mulm.results_[key].theta.shape[1]
170-
for key in mulm.results_])
169+
tmp = sum(mulm.results_[key].theta.shape[1]
170+
for key in mulm.results_)
171171
assert tmp == n
172172

173173

0 commit comments

Comments
 (0)