Skip to content

Commit 6738d9a

Browse files
MNT: Apply pyupgrade suggestions
1 parent d33a05a commit 6738d9a

28 files changed

+54
-58
lines changed

doc/tools/apigen.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ def __init__(self,
4242
module_skip_patterns=None,
4343
other_defines=True
4444
):
45-
""" Initialize package for parsing
45+
r""" Initialize package for parsing
4646
4747
Parameters
4848
----------
@@ -358,7 +358,7 @@ def _survives_exclude(self, matchstr, match_type):
358358
return True
359359

360360
def discover_modules(self):
361-
""" Return module sequence discovered from ``self.package_name``
361+
r""" Return module sequence discovered from ``self.package_name``
362362
363363
364364
Parameters

nibabel/arraywriters.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -438,8 +438,8 @@ def _range_scale(self, in_min, in_max):
438438
# not lose precision because min/max are of fp type.
439439
out_min, out_max = np.array((out_min, out_max), dtype=big_float)
440440
else: # (u)int
441-
out_min, out_max = [int_to_float(v, big_float)
442-
for v in (out_min, out_max)]
441+
out_min, out_max = (int_to_float(v, big_float)
442+
for v in (out_min, out_max))
443443
if self._out_dtype.kind == 'u':
444444
if in_min < 0 and in_max > 0:
445445
raise WriterError('Cannot scale negative and positive '
@@ -562,15 +562,15 @@ def to_fileobj(self, fileobj, order='F', nan2zero=None):
562562

563563
def _iu2iu(self):
564564
# (u)int to (u)int
565-
mn, mx = [as_int(v) for v in self.finite_range()]
565+
mn, mx = (as_int(v) for v in self.finite_range())
566566
# range may be greater than the largest integer for this type.
567567
# as_int needed to work round numpy 1.4.1 int casting bug
568568
out_dtype = self._out_dtype
569569
# Options in this method are scaling using intercept only. These will
570570
# have to pass through ``self.scaler_dtype`` (because the intercept is
571571
# in this type).
572-
o_min, o_max = [as_int(v)
573-
for v in shared_range(self.scaler_dtype, out_dtype)]
572+
o_min, o_max = (as_int(v)
573+
for v in shared_range(self.scaler_dtype, out_dtype))
574574
type_range = o_max - o_min
575575
mn2mx = mx - mn
576576
if mn2mx <= type_range: # might offset be enough?
@@ -619,8 +619,8 @@ def _range_scale(self, in_min, in_max):
619619
in_min, in_max = as_int(in_min), as_int(in_max)
620620
in_range = int_to_float(in_max - in_min, big_float)
621621
# Cast to float for later processing.
622-
in_min, in_max = [int_to_float(v, big_float)
623-
for v in (in_min, in_max)]
622+
in_min, in_max = (int_to_float(v, big_float)
623+
for v in (in_min, in_max))
624624
if out_dtype.kind == 'f':
625625
# Type range, these are also floats
626626
info = type_info(out_dtype)

nibabel/cifti2/cifti2.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -648,8 +648,8 @@ def __init__(self, name=None, voxel_indices_ijk=None, vertices=None):
648648
self.vertices = vertices if vertices is not None else []
649649
for val in self.vertices:
650650
if not isinstance(val, Cifti2Vertices):
651-
raise ValueError(('Cifti2Parcel vertices must be instances of '
652-
'Cifti2Vertices'))
651+
raise ValueError('Cifti2Parcel vertices must be instances of '
652+
'Cifti2Vertices')
653653

654654
@property
655655
def voxel_indices_ijk(self):

nibabel/cifti2/tests/test_axes.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,10 +93,8 @@ def get_axes():
9393
yield get_parcels()
9494
yield get_scalar()
9595
yield get_label()
96-
for elem in get_brain_models():
97-
yield elem
98-
for elem in get_series():
99-
yield elem
96+
yield from get_brain_models()
97+
yield from get_series()
10098

10199

102100
def test_brain_models():

nibabel/cifti2/tests/test_cifti2io_header.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ def test_read_nifti2():
5050
# Error trying to read a CIFTI-2 image from a NIfTI2-only image.
5151
filemap = ci.Cifti2Image.make_file_map()
5252
for k in filemap:
53-
filemap[k].fileobj = io.open(NIFTI2_DATA)
53+
filemap[k].fileobj = open(NIFTI2_DATA)
5454
with pytest.raises(ValueError):
5555
ci.Cifti2Image.from_file_map(filemap)
5656

nibabel/cmdline/diff.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ def get_data_diff(files, max_abs=0, max_rel=0, dtype=np.float64):
234234
# Since we operated on sub-selected values already, we need
235235
# to plug them back in
236236
candidates[
237-
tuple((indexes[sub_thr] for indexes in np.where(candidates)))
237+
tuple(indexes[sub_thr] for indexes in np.where(candidates))
238238
] = False
239239
max_rel_diff = np.max(rel_diff)
240240
else:

nibabel/cmdline/ls.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ def proc_file(f, opts):
145145
freq = np.bincount(inv)
146146
counts = " ".join("%g:%d" % (i, f) for i, f in zip(items, freq))
147147
row += ["@l" + counts]
148-
except IOError as e:
148+
except OSError as e:
149149
verbose(2, f"Failed to obtain stats/counts -- {e}")
150150
row += [_err()]
151151
return row

nibabel/cmdline/parrec2nii.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +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, use --overwrite to overwrite it')
161+
raise OSError(f'Output file "{outfilename}" exists, use --overwrite to overwrite it')
162162

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

nibabel/cmdline/roi.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ def lossless_slice(img, slicers):
2121
def parse_slice(crop, allow_step=True):
2222
if crop is None:
2323
return slice(None)
24-
start, stop, *extra = [int(val) if val else None for val in crop.split(":")]
24+
start, stop, *extra = (int(val) if val else None for val in crop.split(":"))
2525
if len(extra) > 1:
2626
raise ValueError(f"Cannot parse specification: {crop}")
2727
if not allow_step and extra and extra[0] not in (1, None):

nibabel/ecat.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -471,7 +471,7 @@ def get_series_framenumbers(mlist):
471471
try:
472472
frame_dict[frame_stored] = trueframenumbers[true_order] + 1
473473
except IndexError:
474-
raise IOError('Error in header or mlist order unknown')
474+
raise OSError('Error in header or mlist order unknown')
475475
return frame_dict
476476

477477

0 commit comments

Comments
 (0)