From dc550433137f1d7f03b82b65fd977981a37d60f6 Mon Sep 17 00:00:00 2001 From: Martin Vonk Date: Tue, 27 Dec 2022 15:16:36 +0100 Subject: [PATCH] change list[] to List[] to allow for compatibility of type hinting python<3.9 --- pastas/model.py | 6 +++--- pastas/modelplots.py | 10 +++++----- pastas/modelstats.py | 2 +- pastas/plots.py | 10 +++++----- pastas/stressmodels.py | 4 ++-- pastas/typing/__init__.py | 2 +- pastas/typing/typeh.py | 2 +- 7 files changed, 18 insertions(+), 18 deletions(-) diff --git a/pastas/model.py b/pastas/model.py index e4c26fdce..354e2b2c5 100644 --- a/pastas/model.py +++ b/pastas/model.py @@ -26,7 +26,7 @@ from pastas.version import __version__ # Type Hinting -from pastas.typing import Type, Union, Optional, Tuple, pstTm, pstSM, pstNM, pstBS, pstAL, pstMl +from pastas.typing import Type, Union, Optional, Tuple, List, pstTm, pstSM, pstNM, pstBS, pstAL, pstMl class Model: @@ -1189,7 +1189,7 @@ def get_contribution(self, name: str, tmin: Optional[pstTm] = None, tmax: Option return contrib - def get_contributions(self, split: Optional[bool] = True, **kwargs) -> list[Type[Series]]: + def get_contributions(self, split: Optional[bool] = True, **kwargs) -> List[Type[Series]]: """Method to get contributions of all stressmodels. Parameters @@ -1449,7 +1449,7 @@ def get_response_tmax(self, name: str, p: pstAL = None, cutoff: Optional[float] @get_stressmodel def get_stress(self, name: str, tmin: Optional[pstTm] = None, tmax: Optional[pstTm] = None, freq: Optional[str] = None, warmup: Optional[float] = None, - istress: Optional[int] = None, return_warmup: Optional[bool] = False, p: Optional[pstAL] = None) -> Union[Type[Series], list[Type[Series]]]: + istress: Optional[int] = None, return_warmup: Optional[bool] = False, p: Optional[pstAL] = None) -> Union[Type[Series], List[Type[Series]]]: """Method to obtain the stress(es) from the stressmodel. Parameters diff --git a/pastas/modelplots.py b/pastas/modelplots.py index b1ef91370..5fa344cb1 100644 --- a/pastas/modelplots.py +++ b/pastas/modelplots.py @@ -15,7 +15,7 @@ _table_formatter_params, _table_formatter_stderr # Type Hinting -from pastas.typing import Type, Optional, pstAx, pstFi, pstTm, pstMl +from pastas.typing import Type, Optional, List, pstAx, pstFi, pstTm, pstMl logger = logging.getLogger(__name__) @@ -501,7 +501,7 @@ def cum_frequency(self, tmin: Optional[pstTm] = None, tmax: Optional[pstTm] = No obs = self.ml.observations(tmin=tmin, tmax=tmax) return cum_frequency(obs, sim, ax=ax, figsize=figsize, **kwargs) - def block_response(self, stressmodels: Optional[list[str]] = None, ax: Optional[pstAx] = None, figsize: Optional[tuple] = None, + def block_response(self, stressmodels: Optional[List[str]] = None, ax: Optional[pstAx] = None, figsize: Optional[tuple] = None, **kwargs) -> pstAx: """Plot the block response for a specific stressmodels. @@ -540,7 +540,7 @@ def block_response(self, stressmodels: Optional[list[str]] = None, ax: Optional[ plt.legend(legend) return ax - def step_response(self, stressmodels: Optional[list[str]] = None, ax: Optional[pstAx] = None, figsize: Optional[tuple] = None, + def step_response(self, stressmodels: Optional[List[str]] = None, ax: Optional[pstAx] = None, figsize: Optional[tuple] = None, **kwargs) -> pstAx: """Plot the step response for a specific stressmodels. @@ -853,7 +853,7 @@ def summary_pdf(self, tmin: Optional[pstTm] = None, tmax: Optional[pstTm] = None return fig -def _get_height_ratios(ylims: list[list, tuple]) -> list[float]: +def _get_height_ratios(ylims: List[list, tuple]) -> List[float]: height_ratios = [] for ylim in ylims: hr = ylim[1] - ylim[0] @@ -863,7 +863,7 @@ def _get_height_ratios(ylims: list[list, tuple]) -> list[float]: return height_ratios -def _get_stress_series(ml, split: Optional[bool] = True) -> list[Type[Series]]: +def _get_stress_series(ml, split: Optional[bool] = True) -> List[Type[Series]]: stresses = [] for name in ml.stressmodels.keys(): nstress = len(ml.stressmodels[name].stress) diff --git a/pastas/modelstats.py b/pastas/modelstats.py index f962e74e3..097d95662 100644 --- a/pastas/modelstats.py +++ b/pastas/modelstats.py @@ -285,7 +285,7 @@ def aic(self, tmin: Optional[pstTm] = None, tmax: Optional[pstTm] = None) -> flo return metrics.aic(res=res, nparam=nparam) @model_tmin_tmax - def summary(self, tmin: Optional[pstTm] = None, tmax: Optional[pstTm] = None, stats: Optional[list[str]] = None) -> Type[DataFrame]: + def summary(self, tmin: Optional[pstTm] = None, tmax: Optional[pstTm] = None, stats: Optional[List[str]] = None) -> Type[DataFrame]: """Returns a Pandas DataFrame with goodness-of-fit metrics. Parameters diff --git a/pastas/plots.py b/pastas/plots.py index 0e2392e57..393c77bb8 100644 --- a/pastas/plots.py +++ b/pastas/plots.py @@ -15,7 +15,7 @@ from .modelcompare import CompareModels # Type Hinting -from pastas.typing import Type, Optional, pstAL, pstAx, pstFi, pstTm, pstMl +from pastas.typing import Type, Optional, List, pstAL, pstAx, pstFi, pstTm, pstMl logger = logging.getLogger(__name__) @@ -24,7 +24,7 @@ "TrackSolve"] -def compare(models: list[pstMl], adjust_height: Optional[bool] = True, **kwargs) -> pstAx: +def compare(models: List[pstMl], adjust_height: Optional[bool] = True, **kwargs) -> pstAx: """Plot multiple Pastas models in one figure to visually compare models. Note @@ -56,8 +56,8 @@ def compare(models: list[pstMl], adjust_height: Optional[bool] = True, **kwargs) return mc.axes -def series(head: Optional[Type[Series]] = None, stresses: Optional[list[Type[Series]]] = None, hist: Optional[bool] = True, kde: Optional[bool] = False, titles: Optional[bool] = True, - tmin: Optional[pstTm] = None, tmax: Optional[pstTm] = None, labels: Optional[list[str]] = None, figsize: Optional[tuple] = (10, 5)) -> pstAx: +def series(head: Optional[Type[Series]] = None, stresses: Optional[List[Type[Series]]] = None, hist: Optional[bool] = True, kde: Optional[bool] = False, titles: Optional[bool] = True, + tmin: Optional[pstTm] = None, tmax: Optional[pstTm] = None, labels: Optional[List[str]] = None, figsize: Optional[tuple] = (10, 5)) -> pstAx: """Plot all the input time series in a single plot. Parameters @@ -785,7 +785,7 @@ def plot_track_solve(self, params: pstAL): plt.pause(1e-10) self.fig.canvas.draw() - def plot_track_solve_history(self, fig: Optional[pstFi] = None) -> list[pstAx]: + def plot_track_solve_history(self, fig: Optional[pstFi] = None) -> List[pstAx]: """Plot optimization history. Parameters diff --git a/pastas/stressmodels.py b/pastas/stressmodels.py index e5da90cf7..88b263164 100644 --- a/pastas/stressmodels.py +++ b/pastas/stressmodels.py @@ -30,7 +30,7 @@ # Type Hinting -from pastas.typing import Type, Optional, Tuple, Union, pstAL, pstRF, pstRB, pstRV, pstTm, pstMl +from pastas.typing import Type, Optional, Tuple, List, Union, pstAL, pstRF, pstRB, pstRV, pstTm, pstMl logger = getLogger(__name__) @@ -539,7 +539,7 @@ class WellModel(StressModelBase): """ _name = "WellModel" - def __init__(self, stress: list[Type[Series]], rfunc: pstRF, name: str, distances: pstAL, up: Optional[bool] = False, cutoff: Optional[float] = 0.999, + def __init__(self, stress: List[Type[Series]], rfunc: pstRF, name: str, distances: pstAL, up: Optional[bool] = False, cutoff: Optional[float] = 0.999, settings: Optional[str] = "well", sort_wells: Optional[bool] = True): if not (isinstance(rfunc, HantushWellModel) or issubclass(rfunc, HantushWellModel)): diff --git a/pastas/typing/__init__.py b/pastas/typing/__init__.py index a75411c33..bfc1f74e8 100644 --- a/pastas/typing/__init__.py +++ b/pastas/typing/__init__.py @@ -1 +1 @@ -from .typeh import Type, Union, Optional, Tuple, Any, pstAx, pstFi, pstTm, pstMl, pstTS, pstSM, pstNM, pstBS, pstRB, pstRV, pstCB, pstFu, pstRF, pstAL +from .typeh import Type, Union, Optional, Tuple, List, Any, pstAx, pstFi, pstTm, pstMl, pstTS, pstSM, pstNM, pstBS, pstRB, pstRV, pstCB, pstFu, pstRF, pstAL diff --git a/pastas/typing/typeh.py b/pastas/typing/typeh.py index 3729ecea1..4a93c2854 100644 --- a/pastas/typing/typeh.py +++ b/pastas/typing/typeh.py @@ -23,7 +23,7 @@ # Numpy from numpy.typing import ArrayLike # Typing -from typing import Type, Union, Optional, Tuple, Any, TypeVar +from typing import Type, Union, Optional, Tuple, List, Any, TypeVar pstAx = TypeVar("pstAx", bound=_AxesBase) # Matplotlib Axes pstFi = TypeVar("pstFi", bound=FigureBase) # Matplotlib Figure