Skip to content

Commit 092dc9b

Browse files
jond01effigies
andauthored
STY: Apply suggestions from code review
Co-authored-by: Chris Markiewicz <[email protected]>
1 parent 5212c7d commit 092dc9b

31 files changed

+58
-80
lines changed

nibabel/benchmarks/bench_arrayproxy_slicing.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,7 @@ def fmt_sliceobj(sliceobj):
100100

101101
with InTemporaryDirectory():
102102

103-
print(f'Generating test data... '
104-
f'({int(round(np.prod(SHAPE) * 4 / 1048576.0))} MB)')
103+
print(f'Generating test data... ({int(round(np.prod(SHAPE) * 4 / 1048576.0))} MB)')
105104

106105
data = np.array(np.random.random(SHAPE), dtype=np.float32)
107106

@@ -180,8 +179,7 @@ def testfunc():
180179
data[:, 2] = np.nan
181180
data[:, 3] = [r[5] - r[6] for r in results]
182181

183-
rowlbls = [(f'Type {r[0]}, keep_open {r[1]}, '
184-
f'slice {fmt_sliceobj(r[2])}') for r in results]
182+
rowlbls = [f'Type {r[0]}, keep_open {r[1]}, slice {fmt_sliceobj(r[2])}' for r in results]
185183
collbls = ['Time', 'Baseline time', 'Time ratio', 'Memory deviation']
186184

187185
print(rst_table(data, rowlbls, collbls))

nibabel/benchmarks/bench_fileslice.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,7 @@
2020
from ..tmpdirs import InTemporaryDirectory
2121

2222
SHAPE = (64, 64, 32, 100)
23-
ROW_NAMES = [f'axis {i}, len {SHAPE[i]}'
24-
for i in range(len(SHAPE))]
23+
ROW_NAMES = [f'axis {i}, len {dim}' for i, dim in enumerate(SHAPE)]
2524
COL_NAMES = ['mid int',
2625
'step 1',
2726
'half step 1',

nibabel/brikhead.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ def _unpack_var(var):
114114
TEMPLATE_SPACE ORIG
115115
"""
116116

117-
err_msg = (f'Please check HEAD file to ensure it is AFNI compliant. '
117+
err_msg = ('Please check HEAD file to ensure it is AFNI compliant. '
118118
f'Offending attribute:\n{var}')
119119
atype, aname = TYPE_RE.findall(var), NAME_RE.findall(var)
120120
if len(atype) != 1:
@@ -127,7 +127,7 @@ def _unpack_var(var):
127127
try:
128128
attr = [atype(f) for f in attr.split()]
129129
except ValueError:
130-
raise AFNIHeaderError(f'Failed to read variable from HEAD file '
130+
raise AFNIHeaderError('Failed to read variable from HEAD file '
131131
f'due to improper type casting. {err_msg}')
132132
else:
133133
# AFNI string attributes will always start with open single quote and

nibabel/casting.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -296,8 +296,7 @@ def type_info(np_type):
296296
maxexp=16384,
297297
width=width)
298298
else: # don't recognize the type
299-
raise FloatingError(f'We had not expected long double '
300-
f'type {np_type} with info {info}')
299+
raise FloatingError(f'We had not expected long double type {np_type} with info {info}')
301300
return ret
302301

303302

nibabel/cifti2/cifti2.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -291,8 +291,7 @@ def _to_xml_element(self):
291291
v = _float_01(getattr(self, c_))
292292
except ValueError:
293293
raise Cifti2HeaderError(
294-
f'Label invalid {c_} needs to be a '
295-
f'float between 0 and 1. and it is {v}'
294+
f'Label invalid {c_} needs to be a float between 0 and 1. and it is {v}'
296295
)
297296

298297
lab = xml.Element('Label')

nibabel/cifti2/cifti2_axes.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -538,7 +538,7 @@ def to_cifti_brain_structure_name(name):
538538
proposed_name = f'CIFTI_STRUCTURE_{structure.upper()}_{orientation.upper()}'
539539
if proposed_name not in cifti2.CIFTI_BRAIN_STRUCTURES:
540540
raise ValueError(f'{name} was interpreted as {proposed_name}, which is not '
541-
f'a valid CIFTI brain structure')
541+
'a valid CIFTI brain structure')
542542
return proposed_name
543543

544544
@property
@@ -650,7 +650,7 @@ def __add__(self, other):
650650
nvertices = dict(self.nvertices)
651651
for name, value in other.nvertices.items():
652652
if name in nvertices.keys() and nvertices[name] != value:
653-
raise ValueError(f"Trying to concatenate two BrainModels with "
653+
raise ValueError("Trying to concatenate two BrainModels with "
654654
f"inconsistent number of vertices for {name}")
655655
nvertices[name] = value
656656
return self.__class__(
@@ -804,7 +804,7 @@ def from_brain_models(cls, named_brain_models):
804804
for name, _, bm_part in bm.iter_structures():
805805
if name in bm.nvertices.keys():
806806
if name in nvertices.keys() and nvertices[name] != bm.nvertices[name]:
807-
raise ValueError(f"Got multiple conflicting number of "
807+
raise ValueError("Got multiple conflicting number of "
808808
f"vertices for surface structure {name}")
809809
nvertices[name] = bm.nvertices[name]
810810
vertices[name] = bm_part.vertex
@@ -967,7 +967,7 @@ def __add__(self, other):
967967
nvertices = dict(self.nvertices)
968968
for name, value in other.nvertices.items():
969969
if name in nvertices.keys() and nvertices[name] != value:
970-
raise ValueError(f"Trying to concatenate two ParcelsAxis with "
970+
raise ValueError("Trying to concatenate two ParcelsAxis with "
971971
f"inconsistent number of vertices for {name}")
972972
nvertices[name] = value
973973
return self.__class__(

nibabel/cmdline/ls.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ def proc_file(f, opts):
116116
else:
117117
row += ['']
118118
except Exception as e:
119-
verbose(2, f"Failed to obtain qform or sform -- {str(e)}")
119+
verbose(2, f"Failed to obtain qform or sform -- {e}")
120120
if isinstance(h, nib.AnalyzeHeader):
121121
row += ['']
122122
else:
@@ -136,7 +136,7 @@ def proc_file(f, opts):
136136
# just # of elements
137137
row += ["@l[%d]" % np.prod(d.shape)]
138138
# stats
139-
row += [len(d) and f'@l[{np.min(d):.2g}, {np.max(d):.2g}]' or '-']
139+
row += [f'@l[{np.min(d):.2g}, {np.max(d):.2g}]' if len(d) else '-']
140140
if opts.counts:
141141
items, inv = np.unique(d, return_inverse=True)
142142
if len(items) > 1000 and not opts.all_counts:
@@ -146,7 +146,7 @@ def proc_file(f, opts):
146146
counts = " ".join("%g:%d" % (i, f) for i, f in zip(items, freq))
147147
row += ["@l" + counts]
148148
except IOError as e:
149-
verbose(2, f"Failed to obtain stats/counts -- {str(e)}")
149+
verbose(2, f"Failed to obtain stats/counts -- {e}")
150150
row += [_err()]
151151
return row
152152

nibabel/cmdline/parrec2nii.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ def get_opt_parser():
136136

137137
def verbose(msg, indent=0):
138138
if verbose.switch:
139-
print(f"{' ' * indent}{msg}")
139+
print(' ' * indent + msg)
140140

141141

142142
def error(msg, exit_code):
@@ -158,8 +158,7 @@ def proc_file(infile, opts):
158158
else:
159159
outfilename = basefilename + '.nii'
160160
if os.path.isfile(outfilename) and not opts.overwrite:
161-
raise IOError(f'Output file "{outfilename}" exists, '
162-
f'use --overwrite to overwrite it')
161+
raise IOError(f'Output file "{outfilename}" exists, use --overwrite to overwrite it')
163162

164163
# load the PAR header and data
165164
scaling = 'dv' if opts.scaling == 'off' else opts.scaling

nibabel/cmdline/tck2trk.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,7 @@ def main():
4141
filename, _ = os.path.splitext(tractogram)
4242
output_filename = filename + '.trk'
4343
if os.path.isfile(output_filename) and not args.force:
44-
msg = (f"Skipping existing file: '{output_filename}'. "
45-
f"Use -f to overwrite.")
46-
print(msg)
44+
print(f"Skipping existing file: '{output_filename}'. Use -f to overwrite.")
4745
continue
4846

4947
# Build header using infos from the anatomical image.

nibabel/cmdline/trk2tck.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,7 @@ def main():
3131
filename, _ = os.path.splitext(tractogram)
3232
output_filename = filename + '.tck'
3333
if os.path.isfile(output_filename) and not args.force:
34-
msg = (f"Skipping existing file: '{output_filename}'. "
35-
f"Use -f to overwrite.")
36-
print(msg)
34+
print(f"Skipping existing file: '{output_filename}'. Use -f to overwrite.")
3735
continue
3836

3937
trk = nib.streamlines.load(tractogram)

0 commit comments

Comments
 (0)