Skip to content

Commit a162ad1

Browse files
authored
Merge pull request #988 from effigies/mnt/pyupgrade
chore: Drop Python 3.9 support
2 parents fa0032f + 36e147c commit a162ad1

File tree

18 files changed

+97
-62
lines changed

18 files changed

+97
-62
lines changed

.github/workflows/tox.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -94,17 +94,17 @@ jobs:
9494
runs-on: ubuntu-latest
9595
strategy:
9696
matrix:
97-
python-version: ["3.9", "3.10", "3.11", "3.12", "3.13"]
97+
python-version: ["3.10", "3.11", "3.12", "3.13"]
9898
dependencies: [latest, pre]
9999
include:
100-
- python-version: "3.9"
100+
- python-version: "3.10"
101101
dependencies: min
102102
exclude:
103103
# Do not test pre-releases for versions out of SPEC0
104-
- python-version: "3.9"
105-
dependencies: pre
106104
- python-version: "3.10"
107105
dependencies: pre
106+
- python-version: "3.11"
107+
dependencies: pre
108108

109109
env:
110110
DEPENDS: ${{ matrix.dependencies }}

niworkflows/func/tests/test_util.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@
7474

7575
bold_datasets = [[str((datapath / p).absolute()) for p in ds] for ds in bold_datasets]
7676

77-
parameters = zip(bold_datasets, exp_masks)
77+
parameters = zip(bold_datasets, exp_masks, strict=False)
7878

7979
if not bold_datasets:
8080
raise RuntimeError(

niworkflows/interfaces/bids.py

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
import os
2626
import re
2727
import shutil
28-
import sys
2928
from collections import defaultdict
3029
from contextlib import suppress
3130
from json import dumps, loads
@@ -66,15 +65,6 @@
6665
LOGGER = logging.getLogger('nipype.interface')
6766

6867

69-
if sys.version_info < (3, 10): # PY39
70-
builtin_zip = zip
71-
72-
def zip(*args, strict=False): # noqa: A001
73-
if strict and any(len(args[0]) != len(arg) for arg in args):
74-
raise ValueError('strict_zip() requires all arguments to have the same length')
75-
return builtin_zip(*args)
76-
77-
7868
def _none():
7969
return None
8070

@@ -629,7 +619,7 @@ def _run_interface(self, runtime):
629619
self._results['out_path'] = dest_files
630620
self._results['out_meta'] = metadata
631621

632-
for i, (orig_file, dest_file) in enumerate(zip(in_file, dest_files)):
622+
for i, (orig_file, dest_file) in enumerate(zip(in_file, dest_files, strict=False)):
633623
# Set data and header iff changes need to be made. If these are
634624
# still None when it's time to write, just copy.
635625
new_data, new_header = None, None
@@ -1132,7 +1122,7 @@ def _run_interface(self, runtime):
11321122
f'by interpolated patterns ({len(dest_files)}).'
11331123
)
11341124

1135-
for i, (orig_file, dest_file) in enumerate(zip(in_file, dest_files)):
1125+
for i, (orig_file, dest_file) in enumerate(zip(in_file, dest_files, strict=False)):
11361126
out_file = out_path / dest_file
11371127
out_file.parent.mkdir(exist_ok=True, parents=True)
11381128
self._results['out_file'].append(str(out_file))

niworkflows/interfaces/confounds.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ def spike_regressors(
303303
post_final = data.shape[0] + 1
304304
epoch_length = np.diff(sorted(mask | {-1, post_final})) - 1
305305
epoch_end = sorted(mask | {post_final})
306-
for end, length in zip(epoch_end, epoch_length):
306+
for end, length in zip(epoch_end, epoch_length, strict=False):
307307
if length < minimum_contiguous:
308308
mask = mask | set(range(end - length, end))
309309
mask = mask.intersection(indices)

niworkflows/interfaces/images.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,9 @@ def _run_interface(self, runtime):
284284
self._results['out_file'] = fname(suffix='_average')
285285
self._results['out_volumes'] = fname(suffix='_sliced')
286286

287-
sliced = nb.concat_images(i for i, t in zip(nb.four_to_three(img), t_mask) if t)
287+
sliced = nb.concat_images(
288+
i for i, t in zip(nb.four_to_three(img), t_mask, strict=False) if t
289+
)
288290

289291
data = sliced.get_fdata(dtype='float32')
290292
# Data can come with outliers showing very high numbers - preemptively prune

niworkflows/interfaces/itk.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ def _run_interface(self, runtime):
141141
if num_threads == 1:
142142
out_files = [
143143
_applytfms((in_file, in_xfm, ifargs, i, runtime.cwd))
144-
for i, (in_file, in_xfm) in enumerate(zip(in_files, xfms_list))
144+
for i, (in_file, in_xfm) in enumerate(zip(in_files, xfms_list, strict=False))
145145
]
146146
else:
147147
from concurrent.futures import ThreadPoolExecutor
@@ -152,7 +152,9 @@ def _run_interface(self, runtime):
152152
_applytfms,
153153
[
154154
(in_file, in_xfm, ifargs, i, runtime.cwd)
155-
for i, (in_file, in_xfm) in enumerate(zip(in_files, xfms_list))
155+
for i, (in_file, in_xfm) in enumerate(
156+
zip(in_files, xfms_list, strict=False)
157+
)
156158
],
157159
)
158160
)
@@ -264,4 +266,4 @@ def _arrange_xfms(transforms, num_files, tmp_folder):
264266
xfms_T.append(split_xfms)
265267

266268
# Transpose back (only Python 3)
267-
return list(map(list, zip(*xfms_T)))
269+
return list(map(list, zip(*xfms_T, strict=False)))

niworkflows/interfaces/surf.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -743,6 +743,7 @@ def ply2gii(in_file, metadata, out_file=None):
743743
zip(
744744
('SurfaceCenterX', 'SurfaceCenterY', 'SurfaceCenterZ'),
745745
[f'{c:.4f}' for c in surf.centroid],
746+
strict=False,
746747
)
747748
)
748749

niworkflows/interfaces/tests/test_bids.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -361,10 +361,10 @@ def test_DerivativesDataSink_build_path(
361361
]
362362

363363
base = (out_path_base or 'niworkflows') if interface == bintfs.DerivativesDataSink else ''
364-
for out, exp in zip(output, expectation):
364+
for out, exp in zip(output, expectation, strict=False):
365365
assert Path(out).relative_to(base_directory) == Path(base) / exp
366366

367-
for out, exp in zip(output, expectation):
367+
for out, exp in zip(output, expectation, strict=False):
368368
assert Path(out).relative_to(base_directory) == Path(base) / exp
369369
# Regression - some images were given nan scale factors
370370
if out.endswith(('.nii', '.nii.gz')):
@@ -374,7 +374,7 @@ def test_DerivativesDataSink_build_path(
374374
hdr = img.header.from_fileobj(fobj)
375375
assert not np.isnan(hdr['scl_slope'])
376376
assert not np.isnan(hdr['scl_inter'])
377-
for out, chksum in zip(output, checksum):
377+
for out, chksum in zip(output, checksum, strict=False):
378378
if chksum == '335f1394ce90b58bbf27026b6eeec4d2124c11da':
379379
if Version(nb.__version__) < Version('5.3'):
380380
# Nibabel 5.3 avoids unnecessary roundtrips for Cifti2Headers

niworkflows/interfaces/tests/test_images.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ def test_TemplateDimensions(tmp_path):
195195
(0.9, 0.9, 0.9),
196196
]
197197

198-
for i, (shape, zoom) in enumerate(zip(shapes, zooms)):
198+
for i, (shape, zoom) in enumerate(zip(shapes, zooms, strict=False)):
199199
img = nb.Nifti1Image(np.ones(shape, dtype='float32'), np.eye(4))
200200
img.header.set_zooms(zoom)
201201
img.to_filename(tmp_path / f'test{i}.nii')

niworkflows/interfaces/utility.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,7 @@ def _run_interface(self, runtime):
371371
raise ValueError('Number of columns in datasets do not match')
372372

373373
merged = []
374-
for d, j in zip(data, join):
374+
for d, j in zip(data, join, strict=False):
375375
line = '%s\t%s' % ((j, d) if self.inputs.side == 'left' else (d, j))
376376
merged.append(line)
377377

0 commit comments

Comments
 (0)