Skip to content

Commit a02d4d5

Browse files
🚀 feat(*/*) Extend python versions to 3.9 and 3.10 (#76)
* feat(*/*) extend support for python 3.9 and 3.10 --------- Co-authored-by: Fabien Casenave <fabien.casenave@safrangroup.com>
1 parent 5d57c1e commit a02d4d5

10 files changed

Lines changed: 49 additions & 28 deletions

File tree

.github/workflows/testing.yml

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ jobs:
1616
strategy:
1717
matrix:
1818
os: [ubuntu-latest, macos-latest, windows-latest]
19-
python-version: [3.11, 3.12]
19+
python-version: ["3.9", "3.10", "3.11", "3.12"]
2020

2121
steps:
2222
- name: Checkout code
@@ -33,16 +33,14 @@ jobs:
3333
- name: Modify environment.yml with matrix Python version (Linux/macOS)
3434
if: runner.os != 'Windows'
3535
run: |
36-
python_version=${{ matrix.python-version }}
37-
sed -i.bak "s/^ - python=.*/ - python=${python_version}/" environment.yml
36+
sed -i.bak "s/^ - python=.*/ - python=${{ matrix.python-version }}/" environment.yml
3837
3938
- name: Modify environment.yml with matrix Python version (Windows)
4039
if: runner.os == 'Windows'
4140
shell: powershell
4241
run: |
43-
$python_version = '${{ matrix.python-version }}'
4442
$file = 'environment.yml'
45-
(Get-Content $file) -replace '^\s+- python=.*', " - python=$python_version" | Set-Content $file
43+
(Get-Content $file) -replace '^\s+- python=.*', " - python=${{ matrix.python-version }}" | Set-Content $file
4644
4745
- name: Create environment
4846
run: |

environment.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ channels:
33
- conda-forge
44
- nodefaults
55
dependencies:
6-
- python=3.12
6+
- python=3.11
77
##### RUN #####
88
#---# base
99
- tqdm

pyproject.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ build-backend = "setuptools.build_meta"
88
name = "pyplaid"
99
authors = [{name = "Safran", email = "fabien.casenave@safrangroup.com"}]
1010
description = "A package that implements a data model tailored for AI and ML in the context of physics problems"
11-
requires-python = ">=3.11, <3.13"
11+
requires-python = ">=3.9, <3.13"
1212
keywords=[
1313
"machine learning",
1414
"physics",
@@ -21,6 +21,8 @@ classifiers = [
2121
"Operating System :: MacOS",
2222
"Operating System :: POSIX",
2323
"Operating System :: Microsoft :: Windows",
24+
"Programming Language :: Python :: 3.9",
25+
"Programming Language :: Python :: 3.10",
2426
"Programming Language :: Python :: 3.11",
2527
"Programming Language :: Python :: 3.12",
2628
"Topic :: Scientific/Engineering",

src/plaid/bridges/huggingface_bridge.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,15 @@
11
"""Huggingface bridge for PLAID datasets."""
22

33
import pickle
4-
from typing import Callable, Self
4+
import sys
5+
from typing import Callable
6+
7+
if sys.version_info >= (3, 11):
8+
from typing import Self
9+
else: # pragma: no cover
10+
from typing import TypeVar
11+
12+
Self = TypeVar("Self")
513

614
import datasets
715

src/plaid/containers/dataset.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,14 @@
88
#
99

1010
# %% Imports
11+
import sys
1112

12-
try: # pragma: no cover
13+
if sys.version_info >= (3, 11):
1314
from typing import Self
14-
except ImportError: # pragma: no cover
15-
from typing import Any as Self
15+
else: # pragma: no cover
16+
from typing import TypeVar
17+
18+
Self = TypeVar("Self")
1619

1720
import logging
1821
import os

src/plaid/containers/sample.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,14 @@
88
#
99

1010
# %% Imports
11+
import sys
1112

12-
try: # pragma: no cover
13+
if sys.version_info >= (3, 11):
1314
from typing import Self
14-
except ImportError: # pragma: no cover
15-
from typing import Any as Self
15+
else: # pragma: no cover
16+
from typing import TypeVar
17+
18+
Self = TypeVar("Self")
1619

1720
import copy
1821
import glob

src/plaid/post/bisect.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""Utiliy function to plot bisect graphs comparing predictions vs. targets dataset."""
22

33
import subprocess
4+
from typing import Union
45

56
import matplotlib as mpl
67
import matplotlib.pyplot as plt
@@ -77,10 +78,10 @@ def is_dvipng_available(verbose: bool) -> bool:
7778

7879

7980
def plot_bisect(
80-
ref_dataset: Dataset | str,
81-
pred_dataset: Dataset | str,
82-
problem_def: ProblemDefinition | str,
83-
scalar: str | int,
81+
ref_dataset: Union[Dataset, str],
82+
pred_dataset: Union[Dataset, str],
83+
problem_def: Union[ProblemDefinition, str],
84+
scalar: Union[str, int],
8485
save_file_name: str = "bissec_plots",
8586
verbose: bool = False,
8687
) -> None:

src/plaid/post/metrics.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
"""Utility functions for computing and printing metrics for regression problems in PLAID."""
22

3+
from typing import Union
4+
35
import numpy as np
46
import yaml
57
from sklearn.metrics import r2_score
@@ -125,9 +127,9 @@ def pretty_metrics(metrics: dict) -> None:
125127

126128

127129
def compute_metrics(
128-
ref_dataset: Dataset | str,
129-
pred_dataset: Dataset | str,
130-
problem: ProblemDefinition | str,
130+
ref_dataset: Union[Dataset, str],
131+
pred_dataset: Union[Dataset, str],
132+
problem: Union[ProblemDefinition, str],
131133
save_file_name: str = "test_metrics",
132134
verbose: bool = False,
133135
) -> None:

src/plaid/problem_definition.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,14 @@
99

1010
# %% Imports
1111

12-
try: # pragma: no cover
12+
import sys
13+
14+
if sys.version_info >= (3, 11):
1315
from typing import Self
14-
except ImportError: # pragma: no cover
15-
from typing import Any as Self
16+
else: # pragma: no cover
17+
from typing import TypeVar
18+
19+
Self = TypeVar("Self")
1620

1721
import csv
1822
import logging

src/plaid/utils/interpolation.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ def binary_search_vectorized(
6363
def piece_wise_linear_interpolation(
6464
item: float,
6565
item_indices: np.ndarray,
66-
vectors: np.ndarray | dict,
66+
vectors: Union[np.ndarray, dict],
6767
tolerance: float = 1e-4,
6868
) -> np.ndarray:
6969
"""Computes a item interpolation for temporal vectors defined either by item_indices and vectors at these indices.
@@ -101,7 +101,7 @@ def piece_wise_linear_interpolation(
101101
def piece_wise_linear_interpolation_with_map(
102102
item: float,
103103
item_indices: np.ndarray,
104-
vectors: np.ndarray | dict,
104+
vectors: Union[np.ndarray, dict],
105105
vectors_map: list = None,
106106
tolerance: float = 1e-4,
107107
) -> float:
@@ -143,7 +143,7 @@ def piece_wise_linear_interpolation_with_map(
143143

144144

145145
def piece_wise_linear_interpolation_vectorized(
146-
items: list[float], item_indices: np.ndarray, vectors: np.ndarray | dict
146+
items: list[float], item_indices: np.ndarray, vectors: Union[np.ndarray, str]
147147
) -> list[np.ndarray]:
148148
"""piece_wise_linear_interpolation for more than one call (items is now a list or one-dimensional np.ndarray).
149149
@@ -165,7 +165,7 @@ def piece_wise_linear_interpolation_vectorized(
165165
def piece_wise_linear_interpolation_vectorized_with_map(
166166
items: list[float],
167167
item_indices: np.ndarray,
168-
vectors: np.ndarray | dict,
168+
vectors: Union[np.ndarray, dict],
169169
vectors_map: list = None,
170170
) -> list[np.ndarray]:
171171
"""piece_wise_linear_interpolation_with_map for more than one call (items is now a list or one-dimensional np.ndarray).

0 commit comments

Comments
 (0)