Skip to content

Commit fbdfae8

Browse files
authored
Merge pull request #1153 from DimitriPapadopoulos/linter
MNT: Apply refurb suggestions
2 parents d33a05a + ad30f0e commit fbdfae8

File tree

14 files changed

+35
-66
lines changed

14 files changed

+35
-66
lines changed

nibabel/cifti2/tests/test_cifti2.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -326,8 +326,7 @@ def test_matrixindicesmap():
326326
parcel = ci.Cifti2Parcel()
327327

328328
assert mim.volume is None
329-
mim.append(volume)
330-
mim.append(parcel)
329+
mim.extend((volume, parcel))
331330

332331

333332
assert mim.volume == volume

nibabel/cifti2/tests/test_new_cifti2.py

Lines changed: 11 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -232,8 +232,7 @@ def test_dtseries():
232232
series_map = create_series_map((0, ))
233233
geometry_map = create_geometry_map((1, ))
234234
matrix = ci.Cifti2Matrix()
235-
matrix.append(series_map)
236-
matrix.append(geometry_map)
235+
matrix.extend((series_map, geometry_map))
237236
hdr = ci.Cifti2Header(matrix)
238237
data = np.random.randn(13, 10)
239238
img = ci.Cifti2Image(data, hdr)
@@ -254,8 +253,7 @@ def test_dscalar():
254253
scalar_map = create_scalar_map((0, ))
255254
geometry_map = create_geometry_map((1, ))
256255
matrix = ci.Cifti2Matrix()
257-
matrix.append(scalar_map)
258-
matrix.append(geometry_map)
256+
matrix.extend((scalar_map, geometry_map))
259257
hdr = ci.Cifti2Header(matrix)
260258
data = np.random.randn(2, 10)
261259
img = ci.Cifti2Image(data, hdr)
@@ -276,8 +274,7 @@ def test_dlabel():
276274
label_map = create_label_map((0, ))
277275
geometry_map = create_geometry_map((1, ))
278276
matrix = ci.Cifti2Matrix()
279-
matrix.append(label_map)
280-
matrix.append(geometry_map)
277+
matrix.extend((label_map, geometry_map))
281278
hdr = ci.Cifti2Header(matrix)
282279
data = np.random.randn(2, 10)
283280
img = ci.Cifti2Image(data, hdr)
@@ -318,8 +315,7 @@ def test_ptseries():
318315
series_map = create_series_map((0, ))
319316
parcel_map = create_parcel_map((1, ))
320317
matrix = ci.Cifti2Matrix()
321-
matrix.append(series_map)
322-
matrix.append(parcel_map)
318+
matrix.extend((series_map, parcel_map))
323319
hdr = ci.Cifti2Header(matrix)
324320
data = np.random.randn(13, 4)
325321
img = ci.Cifti2Image(data, hdr)
@@ -340,8 +336,7 @@ def test_pscalar():
340336
scalar_map = create_scalar_map((0, ))
341337
parcel_map = create_parcel_map((1, ))
342338
matrix = ci.Cifti2Matrix()
343-
matrix.append(scalar_map)
344-
matrix.append(parcel_map)
339+
matrix.extend((scalar_map, parcel_map))
345340
hdr = ci.Cifti2Header(matrix)
346341
data = np.random.randn(2, 4)
347342
img = ci.Cifti2Image(data, hdr)
@@ -362,8 +357,7 @@ def test_pdconn():
362357
geometry_map = create_geometry_map((0, ))
363358
parcel_map = create_parcel_map((1, ))
364359
matrix = ci.Cifti2Matrix()
365-
matrix.append(geometry_map)
366-
matrix.append(parcel_map)
360+
matrix.extend((geometry_map, parcel_map))
367361
hdr = ci.Cifti2Header(matrix)
368362
data = np.random.randn(10, 4)
369363
img = ci.Cifti2Image(data, hdr)
@@ -384,8 +378,7 @@ def test_dpconn():
384378
parcel_map = create_parcel_map((0, ))
385379
geometry_map = create_geometry_map((1, ))
386380
matrix = ci.Cifti2Matrix()
387-
matrix.append(parcel_map)
388-
matrix.append(geometry_map)
381+
matrix.extend((parcel_map, geometry_map))
389382
hdr = ci.Cifti2Header(matrix)
390383
data = np.random.randn(4, 10)
391384
img = ci.Cifti2Image(data, hdr)
@@ -406,8 +399,7 @@ def test_plabel():
406399
label_map = create_label_map((0, ))
407400
parcel_map = create_parcel_map((1, ))
408401
matrix = ci.Cifti2Matrix()
409-
matrix.append(label_map)
410-
matrix.append(parcel_map)
402+
matrix.extend((label_map, parcel_map))
411403
hdr = ci.Cifti2Header(matrix)
412404
data = np.random.randn(2, 4)
413405
img = ci.Cifti2Image(data, hdr)
@@ -448,8 +440,7 @@ def test_pconnseries():
448440
series_map = create_series_map((2, ))
449441

450442
matrix = ci.Cifti2Matrix()
451-
matrix.append(parcel_map)
452-
matrix.append(series_map)
443+
matrix.extend((parcel_map, series_map))
453444
hdr = ci.Cifti2Header(matrix)
454445
data = np.random.randn(4, 4, 13)
455446
img = ci.Cifti2Image(data, hdr)
@@ -473,8 +464,7 @@ def test_pconnscalar():
473464
scalar_map = create_scalar_map((2, ))
474465

475466
matrix = ci.Cifti2Matrix()
476-
matrix.append(parcel_map)
477-
matrix.append(scalar_map)
467+
matrix.extend((parcel_map, scalar_map))
478468
hdr = ci.Cifti2Header(matrix)
479469
data = np.random.randn(4, 4, 2)
480470
img = ci.Cifti2Image(data, hdr)
@@ -499,8 +489,7 @@ def test_wrong_shape():
499489
brain_model_map = create_geometry_map((1, ))
500490

501491
matrix = ci.Cifti2Matrix()
502-
matrix.append(scalar_map)
503-
matrix.append(brain_model_map)
492+
matrix.extend((scalar_map, brain_model_map))
504493
hdr = ci.Cifti2Header(matrix)
505494

506495
# correct shape is (2, 10)

nibabel/cmdline/dicomfs.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ def __init__(self, fno):
4848
self.fno = fno
4949
self.keep_cache = False
5050
self.direct_io = False
51-
return
5251

5352
def __str__(self):
5453
return 'FileHandle(%d)' % self.fno
@@ -64,7 +63,6 @@ def __init__(self, *args, **kwargs):
6463
self.dicom_path = kwargs.pop('dicom_path', None)
6564
fuse.Fuse.__init__(self, *args, **kwargs)
6665
self.fhs = {}
67-
return
6866

6967
def get_paths(self):
7068
paths = {}
@@ -119,8 +117,7 @@ def readdir(self, path, fh):
119117
return -errno.ENOENT
120118
logger.debug(f'matched {matched_path}')
121119
fnames = [k.encode('ascii', 'replace') for k in matched_path.keys()]
122-
fnames.append('.')
123-
fnames.append('..')
120+
fnames.extend(('.', '..'))
124121
return [fuse.Direntry(f) for f in fnames]
125122

126123
def getattr(self, path):
@@ -190,7 +187,6 @@ def release(self, path, flags, fh):
190187
logger.debug(path)
191188
logger.debug(fh)
192189
del self.fhs[fh.fno]
193-
return
194190

195191

196192
def get_opt_parser():

nibabel/cmdline/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ def verbose(thing, msg):
3232
"""Print `s` if `thing` is less than the `verbose_level`
3333
"""
3434
# TODO: consider using nibabel's logger
35-
if thing <= int(verbose_level):
35+
if thing <= verbose_level:
3636
print(' ' * thing + msg)
3737

3838

nibabel/deprecator.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,8 +161,8 @@ def __call__(self, message, since='', until='',
161161
deprecator : func
162162
Function returning a decorator.
163163
"""
164-
warn_class = warn_class if warn_class else self.warn_class
165-
error_class = error_class if error_class else self.error_class
164+
warn_class = warn_class or self.warn_class
165+
error_class = error_class or self.error_class
166166
messages = [message]
167167
if (since, until) != ('', ''):
168168
messages.append('')

nibabel/dft.py

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ def __init__(self, series, i, si):
5151
self.series = series
5252
self.i = i
5353
self.si = si
54-
return
5554

5655
def __str__(self):
5756
fmt = 'expecting instance number %d, got %d'
@@ -70,7 +69,6 @@ def __init__(self, d):
7069
self.patient_birth_date = d['patient_birth_date']
7170
self.patient_sex = d['patient_sex']
7271
self.series = None
73-
return
7472

7573
def __getattribute__(self, name):
7674
val = object.__getattribute__(self, name)
@@ -103,7 +101,6 @@ def __init__(self, d):
103101
self.bits_allocated = d['bits_allocated']
104102
self.bits_stored = d['bits_stored']
105103
self.storage_instances = None
106-
return
107104

108105
def __getattribute__(self, name):
109106
val = object.__getattribute__(self, name)
@@ -226,7 +223,6 @@ def __init__(self, d):
226223
self.instance_number = d['instance_number']
227224
self.series = d['series']
228225
self.files = None
229-
return
230226

231227
def __getattribute__(self, name):
232228
val = object.__getattribute__(self, name)
@@ -256,7 +252,6 @@ def __exit__(self, type, value, traceback):
256252
if type is None:
257253
self.c.close()
258254
DB.rollback()
259-
return
260255

261256

262257
class _db_change:
@@ -272,7 +267,6 @@ def __exit__(self, type, value, traceback):
272267
DB.commit()
273268
else:
274269
DB.rollback()
275-
return
276270

277271

278272
def _get_subdirs(base_dir, files_dict=None, followlinks=False):
@@ -316,7 +310,6 @@ def update_cache(base_dir, followlinks=False):
316310
else:
317311
query = "INSERT INTO directory (path, mtime) VALUES (?, ?)"
318312
c.execute(query, (dir, mtimes[dir]))
319-
return
320313

321314

322315
def get_studies(base_dir=None, followlinks=False):
@@ -382,7 +375,6 @@ def _update_dir(c, dir, files, studies, series, storage_instances):
382375
SET mtime = ?, storage_instance = ?
383376
WHERE directory = ? AND name = ?"""
384377
c.execute(query, (mtime, si_uid, dir, fname))
385-
return
386378

387379

388380
def _update_file(c, path, fname, studies, series, storage_instances):
@@ -457,7 +449,6 @@ def clear_cache():
457449
c.execute("DELETE FROM storage_instance")
458450
c.execute("DELETE FROM series")
459451
c.execute("DELETE FROM study")
460-
return
461452

462453

463454
CREATE_QUERIES = (

nibabel/nicom/dicomwrappers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -737,7 +737,7 @@ def series_signature(self):
737737
ice = csar.get_ice_dims(self.csa_header)
738738
if ice is not None:
739739
ice = ice[:6] + ice[8:9]
740-
signature['ICE_Dims'] = (ice, lambda x, y: x == y)
740+
signature['ICE_Dims'] = (ice, operator.eq)
741741
return signature
742742

743743
@one_time

nibabel/streamlines/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ def save(tractogram, filename, **kwargs):
129129
" 'TractogramFile' object.")
130130
warnings.warn(msg, ExtensionWarning)
131131

132-
if len(kwargs) > 0:
132+
if kwargs:
133133
msg = ("A 'TractogramFile' object was provided, no need for"
134134
" keyword arguments.")
135135
raise ValueError(msg)

nibabel/streamlines/tck.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -249,12 +249,13 @@ def _write_header(fileobj, header):
249249
Field.VOXEL_TO_RASMM, # Streamlines are always in RAS+ mm.
250250
"count", "datatype", "file"] # Fields being replaced.
251251

252-
lines = []
253-
lines.append(f"count: {header[Field.NB_STREAMLINES]:010}")
254-
lines.append("datatype: Float32LE") # Always Float32LE.
255-
lines.extend([f"{k}: {v}"
256-
for k, v in header.items()
257-
if k not in exclude and not k.startswith("_")])
252+
lines = [
253+
f"count: {header[Field.NB_STREAMLINES]:010}",
254+
"datatype: Float32LE", # Always Float32LE.
255+
]
256+
lines.extend(f"{k}: {v}"
257+
for k, v in header.items()
258+
if k not in exclude and not k.startswith("_"))
258259
out = "\n".join(lines)
259260

260261
# Check the header is well formatted.

nibabel/tests/data/gen_standard.py

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -35,19 +35,17 @@ def _gen_straight_streamline(start, end, steps=3):
3535
return np.array(coords).T
3636

3737
# Generate a 3D 'X' template fitting inside the voxel centered at (0,0,0).
38-
X = []
39-
X.append(_gen_straight_streamline((-0.5, -0.5, -0.5), (0.5, 0.5, 0.5)))
40-
X.append(_gen_straight_streamline((-0.5, 0.5, -0.5), (0.5, -0.5, 0.5)))
41-
X.append(_gen_straight_streamline((-0.5, 0.5, 0.5), (0.5, -0.5, -0.5)))
42-
X.append(_gen_straight_streamline((-0.5, -0.5, 0.5), (0.5, 0.5, -0.5)))
38+
X = [
39+
_gen_straight_streamline((-0.5, -0.5, -0.5), (0.5, 0.5, 0.5)),
40+
_gen_straight_streamline((-0.5, 0.5, -0.5), (0.5, -0.5, 0.5)),
41+
_gen_straight_streamline((-0.5, 0.5, 0.5), (0.5, -0.5, -0.5)),
42+
_gen_straight_streamline((-0.5, -0.5, 0.5), (0.5, 0.5, -0.5)),
43+
]
4344

4445
# Get the coordinates of voxels 'on' in the mask.
4546
coords = np.array(zip(*np.where(mask)))
4647

47-
streamlines = []
48-
for c in coords:
49-
for line in X:
50-
streamlines.append((line + c) * voxel_size)
48+
streamlines = [(line + c) * voxel_size for c in coords for line in X]
5149

5250
return streamlines
5351

0 commit comments

Comments
 (0)