Skip to content

Commit 5aca3f2

Browse files
authored
Merge pull request #1405 from effigies/chore/ruff
chore: Update ruff, address complaints
2 parents f81f5a7 + eaa7200 commit 5aca3f2

36 files changed

+82
-87
lines changed

.git-blame-ignore-revs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# Sun Jan 12 12:22:13 2025 -0500 - [email protected] - sty: ruff format [git-blame-ignore-rev]
2+
40e41208a0f04063b3c4e373a65da1a2a6a275b5
3+
# Sun Jan 12 11:51:49 2025 -0500 - [email protected] - STY: ruff format [git-blame-ignore-rev]
4+
7e5d584910c67851dcfcd074ff307122689b61f5
15
# Sun Jan 1 12:38:02 2023 -0500 - [email protected] - STY: Run pre-commit config on all files
26
d14c1cf282a9c3b19189f490f10c35f5739e24d1
37
# Thu Dec 29 22:53:17 2022 -0500 - [email protected] - STY: Reduce array().astype() and similar constructs

.pre-commit-config.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
exclude: ".*/data/.*"
22
repos:
33
- repo: https://github.com/pre-commit/pre-commit-hooks
4-
rev: v4.6.0
4+
rev: v5.0.0
55
hooks:
66
- id: trailing-whitespace
77
- id: end-of-file-fixer
@@ -13,7 +13,7 @@ repos:
1313
- id: check-merge-conflict
1414
- id: check-vcs-permalinks
1515
- repo: https://github.com/astral-sh/ruff-pre-commit
16-
rev: v0.6.4
16+
rev: v0.9.1
1717
hooks:
1818
- id: ruff
1919
args: [ --fix ]
@@ -24,7 +24,7 @@ repos:
2424
args: [ --select, ISC001, --fix ]
2525
exclude: = ["doc", "tools"]
2626
- repo: https://github.com/pre-commit/mirrors-mypy
27-
rev: v1.11.2
27+
rev: v1.14.1
2828
hooks:
2929
- id: mypy
3030
# Sync with project.optional-dependencies.typing

bin/parrec2nii

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
#!python
2-
"""PAR/REC to NIfTI converter
3-
"""
2+
"""PAR/REC to NIfTI converter"""
43

54
from nibabel.cmdline.parrec2nii import main
65

nibabel/benchmarks/bench_array_to_file.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,24 +29,25 @@ def bench_array_to_file():
2929
sys.stdout.flush()
3030
print_git_title('\nArray to file')
3131
mtime = measure('array_to_file(arr, BytesIO(), np.float32)', repeat)
32-
print('%30s %6.2f' % ('Save float64 to float32', mtime))
32+
fmt = '{:30s} {:6.2f}'.format
33+
print(fmt('Save float64 to float32', mtime))
3334
mtime = measure('array_to_file(arr, BytesIO(), np.int16)', repeat)
34-
print('%30s %6.2f' % ('Save float64 to int16', mtime))
35+
print(fmt('Save float64 to int16', mtime))
3536
# Set a lot of NaNs to check timing
3637
arr[:, :, :, 1] = np.nan
3738
mtime = measure('array_to_file(arr, BytesIO(), np.float32)', repeat)
38-
print('%30s %6.2f' % ('Save float64 to float32, NaNs', mtime))
39+
print(fmt('Save float64 to float32, NaNs', mtime))
3940
mtime = measure('array_to_file(arr, BytesIO(), np.int16)', repeat)
40-
print('%30s %6.2f' % ('Save float64 to int16, NaNs', mtime))
41+
print(fmt('Save float64 to int16, NaNs', mtime))
4142
# Set a lot of infs to check timing
4243
arr[:, :, :, 1] = np.inf
4344
mtime = measure('array_to_file(arr, BytesIO(), np.float32)', repeat)
44-
print('%30s %6.2f' % ('Save float64 to float32, infs', mtime))
45+
print(fmt('Save float64 to float32, infs', mtime))
4546
mtime = measure('array_to_file(arr, BytesIO(), np.int16)', repeat)
46-
print('%30s %6.2f' % ('Save float64 to int16, infs', mtime))
47+
print(fmt('Save float64 to int16, infs', mtime))
4748
# Int16 input, float output
4849
arr = np.random.random_integers(low=-1000, high=1000, size=img_shape)
4950
arr = arr.astype(np.int16)
5051
mtime = measure('array_to_file(arr, BytesIO(), np.float32)', repeat)
51-
print('%30s %6.2f' % ('Save Int16 to float32', mtime))
52+
print(fmt('Save Int16 to float32', mtime))
5253
sys.stdout.flush()

nibabel/benchmarks/bench_arrayproxy_slicing.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ def fmt_sliceobj(sliceobj):
9696
slcstr.append(s)
9797
else:
9898
slcstr.append(str(int(s * SHAPE[i])))
99-
return f"[{', '.join(slcstr)}]"
99+
return f'[{", ".join(slcstr)}]'
100100

101101
with InTemporaryDirectory():
102102
print(f'Generating test data... ({int(round(np.prod(SHAPE) * 4 / 1048576.0))} MB)')

nibabel/benchmarks/bench_finite_range.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,17 @@ def bench_finite_range():
2828
sys.stdout.flush()
2929
print_git_title('\nFinite range')
3030
mtime = measure('finite_range(arr)', repeat)
31-
print('%30s %6.2f' % ('float64 all finite', mtime))
31+
fmt = '{:30s} {:6.2f}'.format
32+
print(fmt('float64 all finite', mtime))
3233
arr[:, :, :, 1] = np.nan
3334
mtime = measure('finite_range(arr)', repeat)
34-
print('%30s %6.2f' % ('float64 many NaNs', mtime))
35+
print(fmt('float64 many NaNs', mtime))
3536
arr[:, :, :, 1] = np.inf
3637
mtime = measure('finite_range(arr)', repeat)
37-
print('%30s %6.2f' % ('float64 many infs', mtime))
38+
print(fmt('float64 many infs', mtime))
3839
# Int16 input, float output
3940
arr = np.random.random_integers(low=-1000, high=1000, size=img_shape)
4041
arr = arr.astype(np.int16)
4142
mtime = measure('finite_range(arr)', repeat)
42-
print('%30s %6.2f' % ('int16', mtime))
43+
print(fmt('int16', mtime))
4344
sys.stdout.flush()

nibabel/benchmarks/bench_load_save.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,20 +34,21 @@ def bench_load_save():
3434
print_git_title('Image load save')
3535
hdr.set_data_dtype(np.float32)
3636
mtime = measure('sio.truncate(0); img.to_file_map()', repeat)
37-
print('%30s %6.2f' % ('Save float64 to float32', mtime))
37+
fmt = '{:30s} {:6.2f}'.format
38+
print(fmt('Save float64 to float32', mtime))
3839
mtime = measure('img.from_file_map(img.file_map)', repeat)
39-
print('%30s %6.2f' % ('Load from float32', mtime))
40+
print(fmt('Load from float32', mtime))
4041
hdr.set_data_dtype(np.int16)
4142
mtime = measure('sio.truncate(0); img.to_file_map()', repeat)
42-
print('%30s %6.2f' % ('Save float64 to int16', mtime))
43+
print(fmt('Save float64 to int16', mtime))
4344
mtime = measure('img.from_file_map(img.file_map)', repeat)
44-
print('%30s %6.2f' % ('Load from int16', mtime))
45+
print(fmt('Load from int16', mtime))
4546
# Set a lot of NaNs to check timing
4647
arr[:, :, :20] = np.nan
4748
mtime = measure('sio.truncate(0); img.to_file_map()', repeat)
48-
print('%30s %6.2f' % ('Save float64 to int16, NaNs', mtime))
49+
print(fmt('Save float64 to int16, NaNs', mtime))
4950
mtime = measure('img.from_file_map(img.file_map)', repeat)
50-
print('%30s %6.2f' % ('Load from int16, NaNs', mtime))
51+
print(fmt('Load from int16, NaNs', mtime))
5152
# Int16 input, float output
5253
arr = np.random.random_integers(low=-1000, high=1000, size=img_shape)
5354
arr = arr.astype(np.int16)
@@ -57,5 +58,5 @@ def bench_load_save():
5758
hdr = img.header
5859
hdr.set_data_dtype(np.float32)
5960
mtime = measure('sio.truncate(0); img.to_file_map()', repeat)
60-
print('%30s %6.2f' % ('Save Int16 to float32', mtime))
61+
print(fmt('Save Int16 to float32', mtime))
6162
sys.stdout.flush()

nibabel/benchmarks/butils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@
55

66
def print_git_title(title):
77
"""Prints title string with git hash if possible, and underline"""
8-
title = f"{title} for git revision {get_info()['commit_hash']}"
8+
title = f'{title} for git revision {get_info()["commit_hash"]}'
99
print(title)
1010
print('-' * len(title))

nibabel/brikhead.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -555,7 +555,7 @@ def filespec_to_file_map(klass, filespec):
555555
fname = fholder.filename
556556
if key == 'header' and not os.path.exists(fname):
557557
for ext in klass._compressed_suffixes:
558-
fname = fname[: -len(ext)] if fname.endswith(ext) else fname
558+
fname = fname.removesuffix(ext)
559559
elif key == 'image' and not os.path.exists(fname):
560560
for ext in klass._compressed_suffixes:
561561
if os.path.exists(fname + ext):

nibabel/cifti2/cifti2.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -294,8 +294,7 @@ def __setitem__(self, key, value):
294294
self._labels[key] = Cifti2Label(*([key] + list(value)))
295295
except ValueError:
296296
raise ValueError(
297-
'Key should be int, value should be sequence '
298-
'of str and 4 floats between 0 and 1'
297+
'Key should be int, value should be sequence of str and 4 floats between 0 and 1'
299298
)
300299

301300
def __delitem__(self, key):

0 commit comments

Comments
 (0)