Skip to content

Commit a08fb3f

Browse files
committed
sty: Use a format template instead of % strings
1 parent f321ca3 commit a08fb3f

File tree

3 files changed

+21
-18
lines changed

3 files changed

+21
-18
lines changed

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_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()

0 commit comments

Comments
 (0)