Skip to content

Commit 4c784a7

Browse files
STY: Apply ruff/pyupgrade rule UP031
UP031 Use format specifiers instead of percent format
1 parent 9aaacfa commit 4c784a7

File tree

8 files changed

+12
-8
lines changed

8 files changed

+12
-8
lines changed

nibabel/analyze.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -515,7 +515,9 @@ def data_to_fileobj(self, data, fileobj, rescale=True):
515515
data = np.asanyarray(data)
516516
shape = self.get_data_shape()
517517
if data.shape != shape:
518-
raise HeaderDataError('Data should be shape (%s)' % ', '.join(str(s) for s in shape))
518+
raise HeaderDataError(
519+
'Data should be shape ({})'.format(', '.join(str(s) for s in shape))
520+
)
519521
out_dtype = self.get_data_dtype()
520522
if rescale:
521523
try:

nibabel/cmdline/diff.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,7 @@ def display_diff(files, diff):
302302

303303
for item in value:
304304
if isinstance(item, dict):
305-
item_str = ', '.join('%s: %s' % i for i in item.items())
305+
item_str = ', '.join('{}: {}'.format(*i) for i in item.items())
306306
elif item is None:
307307
item_str = '-'
308308
else:

nibabel/cmdline/ls.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ def proc_file(f, opts):
112112
and (h.has_data_slope or h.has_data_intercept)
113113
and not h.get_slope_inter() in ((1.0, 0.0), (None, None))
114114
):
115-
row += ['@l*%.3g+%.3g' % h.get_slope_inter()]
115+
row += ['@l*{:.3g}+{:.3g}'.format(*h.get_slope_inter())]
116116
else:
117117
row += ['']
118118

nibabel/dft.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ def __getattribute__(self, name):
231231
WHERE storage_instance = ?
232232
ORDER BY directory, name"""
233233
c.execute(query, (self.uid,))
234-
val = ['%s/%s' % tuple(row) for row in c]
234+
val = ['{}/{}'.format(*tuple(row)) for row in c]
235235
self.files = val
236236
return val
237237

nibabel/freesurfer/mghformat.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -570,7 +570,9 @@ def _write_data(self, mghfile, data, header):
570570
"""
571571
shape = header.get_data_shape()
572572
if data.shape != shape:
573-
raise HeaderDataError('Data should be shape (%s)' % ', '.join(str(s) for s in shape))
573+
raise HeaderDataError(
574+
'Data should be shape ({})'.format(', '.join(str(s) for s in shape))
575+
)
574576
offset = header.get_data_offset()
575577
out_dtype = header.get_data_dtype()
576578
array_to_file(data, mghfile, out_dtype, offset)

nibabel/nifti1.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -552,7 +552,7 @@ def get_sizeondisk(self):
552552
return np.sum([e.get_sizeondisk() for e in self])
553553

554554
def __repr__(self):
555-
return 'Nifti1Extensions(%s)' % ', '.join(str(e) for e in self)
555+
return 'Nifti1Extensions({})'.format(', '.join(str(e) for e in self))
556556

557557
def write_to(self, fileobj, byteswap):
558558
"""Write header extensions to fileobj

nibabel/tests/test_data.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ def test_data_path(with_nimd_env):
160160
tmpfile = pjoin(tmpdir, 'another_example.ini')
161161
with open(tmpfile, 'w') as fobj:
162162
fobj.write('[DATA]\n')
163-
fobj.write('path = %s\n' % '/path/two')
163+
fobj.write('path = {}\n'.format('/path/two'))
164164
assert get_data_path() == tst_list + ['/path/two'] + old_pth
165165

166166

nibabel/tests/test_nifti1.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -538,7 +538,7 @@ def test_slice_times(self):
538538
hdr.set_slice_duration(0.1)
539539
# We need a function to print out the Nones and floating point
540540
# values in a predictable way, for the tests below.
541-
_stringer = lambda val: val is not None and '%2.1f' % val or None
541+
_stringer = lambda val: val is not None and '{:2.1f}'.format(val) or None
542542
_print_me = lambda s: list(map(_stringer, s))
543543
# The following examples are from the nifti1.h documentation.
544544
hdr['slice_code'] = slice_order_codes['sequential increasing']

0 commit comments

Comments
 (0)