Skip to content

Commit

Permalink
change list[] to List[] to allow for compatibility of type hinting py…
Browse files Browse the repository at this point in the history
…thon<3.9
  • Loading branch information
martinvonk committed Dec 27, 2022
1 parent 6e37b42 commit dc55043
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 18 deletions.
6 changes: 3 additions & 3 deletions pastas/model.py
Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
10 changes: 5 additions & 5 deletions pastas/modelplots.py
Expand Up @@ -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__)

Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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]
Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion pastas/modelstats.py
Expand Up @@ -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
Expand Down
10 changes: 5 additions & 5 deletions pastas/plots.py
Expand Up @@ -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__)
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions pastas/stressmodels.py
Expand Up @@ -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__)

Expand Down Expand Up @@ -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)):
Expand Down
2 changes: 1 addition & 1 deletion 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
2 changes: 1 addition & 1 deletion pastas/typing/typeh.py
Expand Up @@ -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
Expand Down

0 comments on commit dc55043

Please sign in to comment.