Skip to content

Commit efa5486

Browse files
authored
Merge pull request #69 from Hendrik-code/chore-python-3.9-compat
Chore python 3.9 compat
2 parents 9f6c6f3 + 33a1aad commit efa5486

File tree

96 files changed

+397
-133
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

96 files changed

+397
-133
lines changed

.github/workflows/tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ jobs:
1414
fail-fast: false
1515
matrix:
1616
os: [ubuntu-latest, windows-latest]
17-
python-version: ["3.10", "3.11", "3.12"]
17+
python-version: ["3.9", "3.10", "3.11", "3.12"]
1818

1919
steps:
2020
- uses: actions/checkout@v4

TPTBox/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from __future__ import annotations
2+
13
# POI
24
import sys
35
from pathlib import Path

TPTBox/core/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from __future__ import annotations
2+
13
# POI
24
# packages
35
from . import bids_files, np_utils, sitk_utils

TPTBox/core/bids_constants.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
### Legal formats ###
22
# https://flexikon.doccheck.com/de/MRT-Sequenz
3+
from __future__ import annotations
4+
35
formats = [
46
"ct",
57
"dixon",

TPTBox/core/bids_files.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ def __init__(
270270
self.sequence_splitting_keys = sequence_splitting_keys
271271

272272
self.sequence_splitting_keys = sequence_splitting_keys
273-
if isinstance(datasets, Path | str):
273+
if isinstance(datasets, (Path, str)):
274274
datasets = [datasets] # type: ignore
275275
if isinstance(parents, str):
276276
parents = [parents]

TPTBox/core/compat.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
from __future__ import annotations
2+
3+
4+
def zip_strict(*iterables):
5+
"""
6+
A strict version of zip that raises a ValueError if the input iterables have different lengths.
7+
8+
Converts each iterable to a list to check lengths. This assumes all iterables are finite.
9+
10+
Args:
11+
*iterables: Finite iterables to be zipped together.
12+
13+
Returns:
14+
An iterator of tuples, where the i-th tuple contains the i-th element from each iterable.
15+
16+
Raises:
17+
ValueError: If the input iterables have different lengths.
18+
"""
19+
lists = [list(it) for it in iterables]
20+
lengths = [len(lst) for lst in lists]
21+
if len(set(lengths)) != 1:
22+
raise ValueError(f"Length mismatch: {lengths}")
23+
return zip(*lists)

TPTBox/core/dicom/dicom2nii_utils.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from __future__ import annotations
2+
13
import json
24
import pickle
35
from copy import deepcopy

TPTBox/core/dicom/dicom_extract.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from __future__ import annotations
2+
13
import os
24
import shutil
35
import sys
@@ -18,6 +20,7 @@
1820
from pydicom.dataset import FileDataset
1921

2022
from TPTBox import BIDS_FILE, Log_Type, Print_Logger
23+
from TPTBox.core.compat import zip_strict
2124
from TPTBox.core.dicom.dicom_header_to_keys import extract_keys_from_json
2225
from TPTBox.core.nii_wrapper import NII
2326

@@ -399,7 +402,7 @@ def _filter_file_type(dicom_types: dict[str, list[str]]):
399402
for sublist in split_lists:
400403
filtered_set.append([item for item in sublist if item in unique_strings]) # noqa: PERF401
401404
# Add to dicom_parts if there are unique strings
402-
for l, i in zip(filtered_set, v, strict=True):
405+
for l, i in zip_strict(filtered_set, v):
403406
dicom_parts[f"{k}_{i}"] = l
404407
return dicom_parts
405408

TPTBox/core/dicom/dicom_header_to_keys.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from __future__ import annotations
2+
13
import re
24
from collections.abc import Callable
35
from pathlib import Path

TPTBox/core/dicom/fix_brocken.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from __future__ import annotations
2+
13
import pickle
24
from pathlib import Path
35

0 commit comments

Comments
 (0)