Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/testing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: ["3.9", "3.10", "3.11", "3.12", "3.13"]
python-version: ["3.10", "3.11", "3.12", "3.13"]

steps:
- uses: actions/checkout@v4
Expand Down
12 changes: 6 additions & 6 deletions pySWATPlus/FileReader.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@

def read_csv(
path: Union[str, Path],
skip_rows: List[int],
usecols: List[str],
filter_by: Dict[str, Union[Any, List[Any], re.Pattern]],
skip_rows: list[int],
usecols: list[str],
filter_by: dict[str, Union[Any, list[Any], re.Pattern[str]]],
separator: str,
encoding: str,
engine: Literal['c', 'python'],
Expand Down Expand Up @@ -97,11 +97,11 @@ class FileReader:

def __init__(
self,
path: str,
path: str | os.PathLike,
has_units: bool = False,
index: Optional[str] = None,
usecols: List[str] = None,
filter_by: Dict[str, Union[Any, List[Any], re.Pattern]] = {}
usecols: Optional[List[str]] = None,
filter_by: Dict[str, Union[Any, List[Any], re.Pattern[str]]] = {}
):

'''
Expand Down
9 changes: 4 additions & 5 deletions pySWATPlus/PymooBestSolution.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import itertools
import shutil
import multiprocessing
from typing import Dict, List, Tuple


class SolutionManager:
Expand All @@ -13,7 +12,7 @@ class SolutionManager:

def __init__(
self
):
) -> None:

self.X = None
self.path = None
Expand All @@ -23,7 +22,7 @@ def __init__(
def add_solution(
self,
X: np.ndarray,
path: Dict[str, str],
path: dict[str, str],
error: float
) -> None:

Expand All @@ -39,7 +38,7 @@ def add_solution(

def get_solution(
self
) -> Tuple[np.ndarray, Dict[str, str], float]:
) -> tuple[np.ndarray, dict[str, str], float]:

"""
Retrieve the best solution.
Expand All @@ -51,7 +50,7 @@ def get_solution(
def add_solutions(
self,
X_array: np.ndarray,
paths_array: List[Dict[str, str]],
paths_array: list[dict[str, str]],
errors_array: np.ndarray
) -> None:

Expand Down
8 changes: 4 additions & 4 deletions pySWATPlus/SWATProblem.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
from typing import Callable, Tuple, Any, Dict, List
import typing
from .SWATProblemMultimodel import SWATProblemMultimodel


class SWATProblem(SWATProblemMultimodel):

def __init__(
self,
params: Dict[str, Tuple[str, List[Tuple[str, str, float, float]]]],
function_to_evaluate: Callable,
params: dict[str, tuple[str, list[tuple[str, str, float, float]]]],
function_to_evaluate: typing.Callable[[dict[typing.Any, typing.Any]], tuple[float, dict[str, str]]],
param_arg_name: str,
n_workers: int = 1,
parallelization: str = 'threads',
debug: bool = False,
**kwargs: Dict[str, Any]
**kwargs: dict[str, typing.Any]
) -> None:

"""
Expand Down
18 changes: 9 additions & 9 deletions pySWATPlus/SWATProblemMultimodel.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from .PymooBestSolution import SolutionManager
import copy
import numpy as np
from typing import Optional, Callable, Tuple, Any, Dict, List
from typing import Optional, Callable, Any
from pymoo.optimize import minimize
from concurrent.futures import ThreadPoolExecutor
import multiprocessing
Expand All @@ -16,7 +16,7 @@ def minimize_pymoo(
seed: Optional[int] = None,
verbose: bool = False,
callback: Optional[Callable] = None
) -> Tuple[Optional[np.ndarray], Optional[str], Optional[float]]:
) -> tuple[Optional[np.ndarray], Optional[str], Optional[float]]:

"""
Perform optimization using the pymoo library.
Expand Down Expand Up @@ -64,18 +64,18 @@ class SWATProblemMultimodel(Problem):

def __init__(
self,
params: Dict[str, Tuple[str, List[Tuple[str, str, float, float]]]],
params: dict[str, tuple[str, list[tuple[str, str, float, float]]]],
function_to_evaluate: Callable,
param_arg_name: str,
n_workers: int = 1,
parallelization: str = 'threads',
ub_prior: Optional[List[int]] = None,
lb_prior: Optional[List[int]] = None,
ub_prior: Optional[list[int]] = None,
lb_prior: Optional[list[int]] = None,
function_to_evaluate_prior: Optional[Callable] = None,
args_function_to_evaluate_prior: Optional[Dict[str, Any]] = None,
args_function_to_evaluate_prior: Optional[dict[str, Any]] = None,
param_arg_name_to_modificate_by_prior_function: Optional[str] = None,
debug: bool = False,
**kwargs: Dict[str, Any]
**kwargs: dict[str, Any]
) -> None:

"""
Expand Down Expand Up @@ -143,10 +143,10 @@ def __init__(
def _evaluate(
self,
X: np.ndarray,
out: Dict[str, Any],
out: dict[str, Any],
*args: Any,
**kwargs: Any
):
) -> None:

"""
Evaluate the objective function for a given set of input parameters.
Expand Down
16 changes: 8 additions & 8 deletions pySWATPlus/TxtinoutReader.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class TxtinoutReader:

def __init__(
self,
path: str
path: Union[str, os.PathLike]
) -> None:

"""
Expand Down Expand Up @@ -298,7 +298,7 @@ def register_file(
has_units: bool = False,
index: Optional[str] = None,
usecols: Optional[List[str]] = None,
filter_by: Dict[str, Union[Any, List[Any], re.Pattern]] = {}
filter_by: dict[str, Union[Any, list[Any], re.Pattern]] = {}
) -> FileReader:

"""
Expand Down Expand Up @@ -451,7 +451,7 @@ def _run_swat(

def run_swat(
self,
params: Dict[str, Tuple[str, List[Tuple[Union[None, str, List[str], re.Pattern], str, Any]]]] = {},
params: dict[str, tuple[str, list[tuple[Union[None, str, list[str], re.Pattern[str]], str, Any]]]] = {},
show_output: bool = True
) -> str:

Expand Down Expand Up @@ -501,7 +501,7 @@ def run_swat(

def run_swat_star(
self,
args: Tuple[Dict[str, Tuple[str, List[Tuple[Union[None, str, List[str], re.Pattern], str, Any]]]], bool]
args: tuple[dict[str, tuple[str, list[tuple[Union[None, str, list[str], re.Pattern[str]], str, Any]]]], bool]
) -> str:

"""
Expand All @@ -523,7 +523,7 @@ def copy_and_run(
self,
target_dir: str,
overwrite: bool = False,
params: Dict[str, Tuple[str, List[Tuple[Union[None, str, List[str], re.Pattern], str, Any]]]] = {},
params: dict[str, tuple[str, list[tuple[Union[None, str, list[str], re.Pattern[str]], str, Any]]]] = {},
show_output: bool = True
) -> str:

Expand All @@ -549,7 +549,7 @@ def copy_and_run(

def copy_and_run_star(
self,
args: Tuple[str, bool, Dict[str, Tuple[str, List[Tuple[Union[None, str, List[str], re.Pattern], str, Any]]]], bool]
args: Tuple[str, bool, Dict[str, Tuple[str, List[Tuple[Union[None, str, List[str], re.Pattern[str]], str, Any]]]], bool]
) -> str:

"""
Expand All @@ -569,9 +569,9 @@ def copy_and_run_star(

def run_parallel_swat(
self,
params: List[Dict[str, Tuple[str, List[Tuple[Union[None, str, List[str], re.Pattern], str, Any]]]]],
params: list[dict[str, tuple[str, list[tuple[Union[None, str, list[str], re.Pattern[str]], str, Any]]]]],
n_workers: int = 1,
target_dir: str = None,
target_dir: Optional[str] = None,
parallelization: str = 'threads'
) -> List[str]:

Expand Down
12 changes: 10 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ name = "pySWATPlus"
description = "Running and calibrating default or custom SWAT+ projects with Python"
dynamic = ["version"]
readme = "README.md"
requires-python = ">=3.9"
requires-python = ">=3.10"
license = {text = "GPL-3.0"}
authors = [
{ name = "Joan Saló", email = "[email protected]" }
Expand Down Expand Up @@ -54,4 +54,12 @@ testpaths = [

[tool.setuptools_scm]
version_scheme = "post-release"
local_scheme = "no-local-version"
local_scheme = "no-local-version"


[tool.mypy]
files = [
"pySWATPlus"
]
ignore_missing_imports = true
strict = true
2 changes: 2 additions & 0 deletions tests/test_filereader.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,6 @@ def test_get_df(
assert df.shape[0] == 260


def test_github():

assert str(1) == '1'