Skip to content

Commit 15a906e

Browse files
authored
Merge pull request #574 from DimitriPapadopoulos/RUF
Apply ruff rules (RUF)
2 parents e03aae0 + 8e10c2c commit 15a906e

File tree

10 files changed

+30
-24
lines changed

10 files changed

+30
-24
lines changed

nipy/algorithms/registration/affine.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -345,10 +345,10 @@ def compose(self, other):
345345
return a
346346

347347
def __str__(self):
348-
string = f'translation : {str(self.translation)}\n'
349-
string += f'rotation : {str(self.rotation)}\n'
350-
string += f'scaling : {str(self.scaling)}\n'
351-
string += f'pre-rotation: {str(self.pre_rotation)}'
348+
string = f'translation : {self.translation}\n'
349+
string += f'rotation : {self.rotation}\n'
350+
string += f'scaling : {self.scaling}\n'
351+
string += f'pre-rotation: {self.pre_rotation}'
352352
return string
353353

354354
def inv(self):
@@ -388,8 +388,8 @@ def from_matrix44(self, aff):
388388
self._vec12 = vec12
389389

390390
def __str__(self):
391-
string = f'translation : {str(self.translation)}\n'
392-
string += f'rotation : {str(self.rotation)}\n'
391+
string = f'translation : {self.translation}\n'
392+
string += f'rotation : {self.rotation}\n'
393393
return string
394394

395395

@@ -430,9 +430,9 @@ def _set_param(self, p):
430430
param = property(Affine._get_param, _set_param)
431431

432432
def __str__(self):
433-
string = f'translation : {str(self.translation)}\n'
434-
string += f'rotation : {str(self.rotation)}\n'
435-
string += f'scaling : {str(self.scaling[0])}\n'
433+
string = f'translation : {self.translation}\n'
434+
string += f'rotation : {self.rotation}\n'
435+
string += f'scaling : {self.scaling[0]}\n'
436436
return string
437437

438438

nipy/algorithms/statistics/formula/formulae.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1061,7 +1061,7 @@ def get_term(self, level):
10611061
"""
10621062
if level not in self.levels:
10631063
raise ValueError('level not found')
1064-
return self[f"{self.name}_{str(level)}"]
1064+
return self[f"{self.name}_{level}"]
10651065

10661066
def _getmaineffect(self, ref=-1):
10671067
v = list(self._terms.copy())

nipy/algorithms/statistics/rft.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,7 @@ def __repr__(self):
343343
m = repr(self.m)
344344
else:
345345
m = f'{self.m:f}'
346-
return f"ECquasi({repr(self.coeffs)}, m={m}, exponent={self.exponent:f})"
346+
return f"ECquasi({self.coeffs!r}, m={m}, exponent={self.exponent:f})"
347347

348348
__str__ = __repr__
349349
__rsub__ = __sub__

nipy/algorithms/statistics/tests/test_intrinsic_volumes.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# emacs: -*- mode: python; py-indent-offset: 4; indent-tabs-mode: nil -*-
22
# vi: set ft=python sts=4 ts=4 sw=4 et:
33

4-
from itertools import combinations
4+
from itertools import chain, combinations
55

66
import numpy as np
77
import numpy.linalg as npl
@@ -192,7 +192,7 @@ def test_ec():
192192
assert_almost_equal(f(box1), 1)
193193
# While we're here, test we can use different dtypes, and that values
194194
# other than 0 or 1 raise an error.
195-
for dtt in sum([SCTYPES[t] for t in ('int', 'uint', 'float')], []):
195+
for dtt in chain.from_iterable(SCTYPES[t] for t in ('int', 'uint', 'float')):
196196
box1_again = box1.copy().astype(dtt)
197197
assert_almost_equal(f(box1_again), 1)
198198
box1_again[(10,) * i] = 2

nipy/algorithms/statistics/tests/test_quantile.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
""" Test quartile functions
22
"""
33

4+
from itertools import chain
5+
46
import numpy as np
57
from numpy import median as np_median
68
from numpy.testing import assert_array_almost_equal, assert_array_equal
@@ -10,9 +12,11 @@
1012

1113
from .._quantile import _median, _quantile
1214

13-
NUMERIC_TYPES = sum([SCTYPES[t]
14-
for t in ('int', 'uint', 'float', 'complex')],
15-
[])
15+
NUMERIC_TYPES = list(
16+
chain.from_iterable(
17+
SCTYPES[t] for t in ("int", "uint", "float", "complex")
18+
)
19+
)
1620

1721

1822
def another_percentile(arr, pct, axis):

nipy/core/reference/array_coords.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ def from_shape(coordmap, shape):
188188

189189
def __repr__(self):
190190
return "ArrayCoordMap(\n coordmap=" + \
191-
'\n '.join(repr(self.coordmap).split('\n')) + f',\n shape={repr(self.shape)}' + '\n)'
191+
'\n '.join(repr(self.coordmap).split('\n')) + f',\n shape={self.shape!r}' + '\n)'
192192

193193

194194
def _slice(coordmap, shape, *slices):

nipy/core/reference/coordinate_map.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -423,9 +423,9 @@ def __copy__(self):
423423

424424
def __repr__(self):
425425
if self.inverse_function is None:
426-
return f"CoordinateMap(\n function_domain={self.function_domain},\n function_range={self.function_range},\n function={repr(self.function)}\n )"
426+
return f"CoordinateMap(\n function_domain={self.function_domain},\n function_range={self.function_range},\n function={self.function!r}\n )"
427427
else:
428-
return f"CoordinateMap(\n function_domain={self.function_domain},\n function_range={self.function_range},\n function={repr(self.function)},\n inverse_function={repr(self.inverse_function)}\n )"
428+
return f"CoordinateMap(\n function_domain={self.function_domain},\n function_range={self.function_range},\n function={self.function!r},\n inverse_function={self.inverse_function!r}\n )"
429429

430430

431431
def _checkfunction(self):
@@ -1370,7 +1370,7 @@ def renamed_domain(mapping, newnames, name=''):
13701370

13711371
for key in list(newnames):
13721372
if key not in mapping.function_domain.coord_names:
1373-
raise ValueError(f'no domain coordinate named {str(key)}')
1373+
raise ValueError(f'no domain coordinate named {key}')
13741374

13751375
new_coord_names = []
13761376
for n in mapping.function_domain.coord_names:
@@ -1434,7 +1434,7 @@ def renamed_range(mapping, newnames):
14341434

14351435
for key in list(newnames):
14361436
if key not in mapping.function_range.coord_names:
1437-
raise ValueError(f'no range coordinate named {str(key)}')
1437+
raise ValueError(f'no range coordinate named {key}')
14381438

14391439
new_coord_names = []
14401440
for n in mapping.function_range.coord_names:

nipy/modalities/fmri/fmristat/hrf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ def approx(time, delta):
188188
approx.dinverse,
189189
approx.forward,
190190
approx.dforward) = invertR(delta, approx.coef)
191-
dhrf = implemented_function(f'd{str(hrf2decompose)}', dhrft)
191+
dhrf = implemented_function(f'd{hrf2decompose}', dhrft)
192192
return [hrf2decompose, dhrf], approx
193193

194194

nipy/utils/perlpie.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ def perl_dash_pie(oldstr, newstr, dry_run=None):
9696
Error while executing perl_dash_pie command:
9797
{cmd}
9898
Error:
99-
{str(err)}
99+
{err}
100100
"""
101101
raise Exception(msg)
102102

nipy/utils/tests/test_arrays.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
""" Testing arrays module
22
"""
33

4+
from itertools import chain
5+
46
import numpy as np
57
import pytest
68
from numpy.testing import assert_array_almost_equal, assert_array_equal
@@ -13,7 +15,7 @@
1315
def test_strides_from():
1416
for shape in ((3,), (2,3), (2,3,4), (5,4,3,2)):
1517
for order in 'FC':
16-
for dtype in sum(SCTYPES.values(), []):
18+
for dtype in chain.from_iterable(SCTYPES.values()):
1719
if dtype is bytes:
1820
dtype = 'S3'
1921
elif dtype is str:

0 commit comments

Comments
 (0)