8000 STY: Enforce ruff/pyupgrade rules (UP) by DimitriPapadopoulos · Pull Request #1351 · nipy/nibabel · GitHub
[go: up one dir, main page]

Skip to content

STY: Enforce ruff/pyupgrade rules (UP) #1351

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 4 commits into from
Sep 22, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
STY: Apply ruff/pyupgrade rule UP031
UP031 Use format specifiers instead of percent format
  • Loading branch information
DimitriPapadopoulos committed Sep 22, 2024
commit 4c784a700578d69792724deea24f1633a9942b85
4 changes: 3 additions & 1 deletion nibabel/analyze.py
Original file line number Diff line number Diff line change
Expand Up @@ -515,7 +515,9 @@ def data_to_fileobj(self, data, fileobj, rescale=True):
data = np.asanyarray(data)
shape = self.get_data_shape()
if data.shape != shape:
raise HeaderDataError('Data should be shape (%s)' % ', '.join(str(s) for s in shape))
raise HeaderDataError(
'Data should be shape ({})'.format(', '.join(str(s) for s in shape))
)
out_dtype = self.get_data_dtype()
if rescale:
try:
Expand Down
2 changes: 1 addition & 1 deletion nibabel/cmdline/diff.py
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ def display_diff(files, diff):

for item in value:
if isinstance(item, dict):
item_str = ', '.join('%s: %s' % i for i in item.items())
item_str = ', '.join('{}: {}'.format(*i) for i in item.items())
elif item is None:
item_str = '-'
else:
Expand Down
2 changes: 1 addition & 1 deletion nibabel/cmdline/ls.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ def proc_file(f, opts):
and (h.has_data_slope or h.has_data_intercept)
and not h.get_slope_inter() in ((1.0, 0.0), (None, None))
):
row += ['@l*%.3g+%.3g' % h.get_slope_inter()]
row += ['@l*{:.3g}+{:.3g}'.format(*h.get_slope_inter())]
else:
row += ['']

Expand Down
2 changes: 1 addition & 1 deletion nibabel/dft.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ def __getattribute__(self, name):
WHERE storage_instance = ?
ORDER BY directory, name"""
c.execute(query, (self.uid,))
val = ['%s/%s' % tuple(row) for row in c]
val = ['{}/{}'.format(*tuple(row)) for row in c]
self.files = val
return val

Expand Down
4 changes: 3 additions & 1 deletion nibabel/freesurfer/mghformat.py
Original file line number Diff line number Diff line change
8000 Expand Up @@ -570,7 +570,9 @@ def _write_data(self, mghfile, data, header):
"""
shape = header.get_data_shape()
if data.shape != shape:
raise HeaderDataError('Data should be shape (%s)' % ', '.join(str(s) for s in shape))
raise HeaderDataError(
'Data should be shape ({})'.format(', '.join(str(s) for s in shape))
)
offset = header.get_data_offset()
out_dtype = header.get_data_dtype()
array_to_file(data, mghfile, out_dtype, offset)
Expand Down
2 changes: 1 addition & 1 deletion nibabel/nifti1.py
Original file line number Diff line number Diff line change
Expand Up @@ -552,7 +552,7 @@ def get_sizeondisk(self):
return np.sum([e.get_sizeondisk() for e in self])

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

def write_to(self, fileobj, byteswap):
"""Write header extensions to fileobj
Expand Down
2 changes: 1 addition & 1 deletion nibabel/tests/test_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ def test_data_path(with_nimd_env):
tmpfile = pjoin(tmpdir, 'another_example.ini')
with open(tmpfile, 'w') as fobj:
fobj.write('[DATA]\n')
fobj.write('path = %s\n' % '/path/two')
fobj.write('path = {}\n'.format('/path/two'))
assert get_data_path() == tst_list + ['/path/two'] + old_pth


Expand Down
2 changes: 1 addition & 1 deletion nibabel/tests/test_nifti1.py
Original file line number Diff line number Diff line change
Expand Up @@ -538,7 +538,7 @@ def test_slice_times(self):
hdr.set_slice_duration(0.1)
# We need a function to print out the Nones and floating point
# values in a predictable way, for the tests below.
_stringer = lambda val: val is not None and '%2.1f' % val or None
_stringer = lambda val: val is not None and '{:2.1f}'.format(val) or None
_print_me = lambda s: list(map(_stringer, s))
# The following examples are from the nifti1.h documentation.
hdr['slice_code'] = slice_order_codes['sequential increasing']
Expand Down
0