Skip to content

Commit

Permalink
Merge pull request #125 from pastas/some_fixes
Browse files Browse the repository at this point in the history
Some minor fixes
  • Loading branch information
dbrakenhoff authored Jun 26, 2024
2 parents 0f5d21f + 01a5582 commit 508b1f9
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 1 deletion.
32 changes: 32 additions & 0 deletions pastastore/base.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import functools
import json
import warnings

# import weakref
from abc import ABC, abstractmethod, abstractproperty
from collections.abc import Iterable
from itertools import chain
Expand All @@ -20,6 +22,34 @@
warnings.showwarning = _custom_warning


# def weak_lru(maxsize=128, typed=False):
# """LRU Cache decorator that keeps a weak reference to 'self'.

# From https://stackoverflow.com/a/68052994/10596229.

# Parameters
# ----------
# maxsize : int, optional
# maximum size of cache, by default 128
# typed : bool, optional
# whether to differentiate between types, by default False

# """

# def wrapper(func):
# @functools.lru_cache(maxsize, typed)
# def _func(_self, *args, **kwargs):
# return func(_self(), *args, **kwargs)

# @functools.wraps(func)
# def inner(self, *args, **kwargs):
# return _func(weakref.ref(self), *args, **kwargs)

# return inner

# return wrapper


class BaseConnector(ABC):
"""Base Connector class.
Expand Down Expand Up @@ -1260,7 +1290,9 @@ def _meta_list_to_frame(metalist: list, names: list):
meta = pd.DataFrame(metalist)
elif len(metalist) == 0:
meta = pd.DataFrame()

meta.index = names
meta.index.name = "name"
return meta

def _parse_model_dict(self, mdict: dict, update_ts_settings: bool = False):
Expand Down
6 changes: 6 additions & 0 deletions pastastore/store.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from pastastore.connectors import DictConnector
from pastastore.plotting import Maps, Plots
from pastastore.util import _custom_warning
from pastastore.version import PASTAS_GEQ_150
from pastastore.yaml_interface import PastastoreYAML

FrameorSeriesUnion = Union[pd.DataFrame, pd.Series]
Expand Down Expand Up @@ -573,6 +574,7 @@ def create_model(
name: str,
modelname: str = None,
add_recharge: bool = True,
add_ar_noisemodel: bool = False,
recharge_name: str = "recharge",
) -> ps.Model:
"""Create a pastas Model.
Expand All @@ -587,6 +589,8 @@ def create_model(
add recharge to the model by looking for the closest
precipitation and evaporation time series in the stresses
library, by default True
add_ar1_noisemodel : bool, optional
add AR(1) noise model to the model, by default False
recharge_name : str
name of the RechargeModel
Expand All @@ -613,6 +617,8 @@ def create_model(
ml = ps.Model(ts, name=modelname, metadata=meta)
if add_recharge:
self.add_recharge(ml, recharge_name=recharge_name)
if add_ar_noisemodel and PASTAS_GEQ_150:
ml.add_noisemodel(ps.ArNoiseModel())
return ml
else:
raise ValueError("Empty time series!")
Expand Down
33 changes: 32 additions & 1 deletion pastastore/version.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,38 @@
# ruff: noqa: D100
from importlib import import_module, metadata
from platform import python_version

import pastas as ps
from packaging.version import parse as parse_version

PASTAS_VERSION = parse_version(ps.__version__)
PASTAS_LEQ_022 = PASTAS_VERSION <= parse_version("0.22.0")
PASTAS_GEQ_150 = PASTAS_VERSION >= parse_version("1.5.0")

__version__ = "1.5.0"


def show_versions(optional=False) -> None:
"""Print the version of dependencies.
Parameters
----------
optional : bool, optional
Print the version of optional dependencies, by default False
"""
msg = (
f"Python version : {python_version()}\n"
f"Pandas version : {metadata.version('pandas')}\n"
f"Matplotlib version : {metadata.version('matplotlib')}\n"
f"Pastas version : {metadata.version('pastas')}\n"
f"PyYAML version : {metadata.version('pyyaml')}\n"
)
if optional:
msg += "\nArcticDB version : "
try:
import_module("arcticdb")
msg += f"{metadata.version('arctidb')}"
except ImportError:
msg += "Not Installed"

__version__ = "1.4.0"
print(msg)

0 comments on commit 508b1f9

Please sign in to comment.