Skip to content

Apply ruff/flake8-comprehensions preview rules (C4) #578

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

Merged
merged 1 commit into from
Oct 6, 2024
Merged
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/users/plots/hrf_different.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@

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])
na = ba * sum(glover.subs(T, T - t) for t in ta)
nb = bb * sum(afni.subs(T, T - t) for t in tb)

nav = lambdify_t(na)
nbv = lambdify_t(nb)
Expand Down
4 changes: 2 additions & 2 deletions doc/users/plots/neuronal_block.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@

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
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

Nn = N.subs(ba,1)
Expand Down
4 changes: 2 additions & 2 deletions doc/users/plots/neuronal_event.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
ba = Symbol('ba')
bb = Symbol('bb')
t = Symbol('t')
fa = sum([Heaviside(t - _t) for _t in ta]) * ba
fb = sum([Heaviside(t - _t) for _t in tb]) * bb
fa = sum(Heaviside(t - _t) for _t in ta) * ba
fb = sum(Heaviside(t - _t) for _t in tb) * bb
N = fa + fb

Nn = N.subs(ba, 1)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ def test_set_fov():
R = HistogramRegistration(I, J)
R.set_fov(npoints=np.prod(I.shape))
assert R._from_data.shape == I.shape
half_shape = tuple([I.shape[i] / 2 for i in range(3)])
half_shape = tuple(I.shape[i] / 2 for i in range(3))
R.set_fov(spacing=(2, 2, 2))
assert R._from_data.shape == half_shape
R.set_fov(corner=half_shape)
Expand Down
2 changes: 1 addition & 1 deletion nipy/algorithms/statistics/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ def cube_with_strides_center(center=[0,0,0],
for m in maximal:
nm = [vertices[j] for j in m]
mm.append(nm)
maximal = [tuple([vertices[j] for j in m]) for m in maximal]
maximal = [tuple(vertices[j] for j in m) for m in maximal]
return complex(maximal)


Expand Down
2 changes: 1 addition & 1 deletion nipy/core/reference/array_coords.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ def from_shape(coordmap, shape):
are 'array' coordinates.

"""
slices = tuple([slice(0,s,1) for s in shape])
slices = tuple(slice(0,s,1) for s in shape)
return Grid(coordmap)[slices]

def __repr__(self):
Expand Down
2 changes: 1 addition & 1 deletion nipy/core/reference/slices.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,4 +222,4 @@ def bounding_box(coordmap, shape):
((2.0, 31.0), (4.0, 121.0), (6.0, 101.0))
"""
e = ArrayCoordMap.from_shape(coordmap, shape)
return tuple([(r.min(), r.max()) for r in e.transposed_values])
return tuple((r.min(), r.max()) for r in e.transposed_values)
2 changes: 1 addition & 1 deletion nipy/io/tests/test_save.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def test_save3(in_tmp_path):
data = tmp.get_fdata().copy()
img2 = api.Image(data, tmp.coordmap, tmp.metadata)
del tmp
assert tuple([img.shape[l] for l in [3,2,1,0]]) == img2.shape
assert tuple(img.shape[l] for l in [3,2,1,0]) == img2.shape
a = np.transpose(img.get_fdata(), [3,2,1,0])
assert not np.allclose(img.affine, img2.affine)
assert np.allclose(a, img2.get_fdata())
Expand Down
6 changes: 3 additions & 3 deletions nipy/labs/tests/test_statistical_mapping.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,17 +53,17 @@ def test_6():
img = make_surrogate_data()
clusters, info = cluster_stats(img, img, height_th=.05,
height_control='fdr', cluster_th=0, nulls={})
print(len(clusters), sum([c['size'] for c in clusters]))
print(len(clusters), sum(c['size'] for c in clusters))
assert len(clusters)==4

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

def test_8():
img = make_surrogate_data()
clusters, info = cluster_stats(img, img, height_th=.001, height_control='fpr', cluster_th=0, nulls={})
nstv = sum([c['size'] for c in clusters])
nstv = sum(c['size'] for c in clusters)
assert nstv==36
4 changes: 2 additions & 2 deletions nipy/modalities/fmri/tests/test_glm.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,8 @@ def test_glm_ar():
mulm, n, p, q = ar1_glm()
assert len(mulm.labels_) == n
assert len(mulm.results_) > 1
tmp = sum([mulm.results_[key].theta.shape[1]
for key in mulm.results_])
tmp = sum(mulm.results_[key].theta.shape[1]
for key in mulm.results_)
assert tmp == n


Expand Down
Loading