From c0d9b8b7fc60fe56fe477cff9dbfa1caf7ca09f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dav=C3=ADd=20Brakenhoff?= Date: Sun, 10 Sep 2023 15:00:21 +0200 Subject: [PATCH] add default Connector add some type hints make imports more explicit --- docs/conf.py | 1 - pastastore/__init__.py | 8 ++++---- pastastore/base.py | 4 ++-- pastastore/connectors.py | 4 ++-- pastastore/store.py | 20 +++++++++++++------- pastastore/util.py | 2 +- pastastore/version.py | 2 +- pastastore/yaml_interface.py | 6 +++--- 8 files changed, 26 insertions(+), 21 deletions(-) diff --git a/docs/conf.py b/docs/conf.py index cb90b729..1da1d1af 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -125,7 +125,6 @@ # # html_sidebars = {} - # -- Options for HTMLHelp output --------------------------------------------- # Output file base name for HTML help builder. diff --git a/pastastore/__init__.py b/pastastore/__init__.py index 1ae7869b..57aad169 100644 --- a/pastastore/__init__.py +++ b/pastastore/__init__.py @@ -1,10 +1,10 @@ -from . import connectors, util -from .connectors import ( +from pastastore import connectors, util +from pastastore.connectors import ( ArcticConnector, ArcticDBConnector, DictConnector, PasConnector, PystoreConnector, ) -from .store import PastaStore -from .version import __version__ +from pastastore.store import PastaStore +from pastastore.version import __version__ diff --git a/pastastore/base.py b/pastastore/base.py index c53825c7..ffe98c82 100644 --- a/pastastore/base.py +++ b/pastastore/base.py @@ -13,8 +13,8 @@ from pastas.io.pas import PastasEncoder from tqdm.auto import tqdm -from .util import ItemInLibraryException, _custom_warning, validate_names -from .version import PASTAS_LEQ_022 +from pastastore.util import ItemInLibraryException, _custom_warning, validate_names +from pastastore.version import PASTAS_LEQ_022 FrameorSeriesUnion = Union[pd.DataFrame, pd.Series] warnings.showwarning = _custom_warning diff --git a/pastastore/connectors.py b/pastastore/connectors.py index 146f3bb5..465be383 100644 --- a/pastastore/connectors.py +++ b/pastastore/connectors.py @@ -8,8 +8,8 @@ import pandas as pd from pastas.io.pas import PastasEncoder, pastas_hook -from .base import BaseConnector, ConnectorUtil, ModelAccessor -from .util import _custom_warning +from pastastore.base import BaseConnector, ConnectorUtil, ModelAccessor +from pastastore.util import _custom_warning FrameorSeriesUnion = Union[pd.DataFrame, pd.Series] warnings.showwarning = _custom_warning diff --git a/pastastore/store.py b/pastastore/store.py index ea57f4ea..15268d2d 100644 --- a/pastastore/store.py +++ b/pastastore/store.py @@ -10,9 +10,11 @@ from pastas.io.pas import pastas_hook from tqdm.auto import tqdm -from .plotting import Maps, Plots -from .util import _custom_warning -from .yaml_interface import PastastoreYAML +from pastastore.base import BaseConnector +from pastastore.connectors import DictConnector +from pastastore.plotting import Maps, Plots +from pastastore.util import _custom_warning +from pastastore.yaml_interface import PastastoreYAML FrameorSeriesUnion = Union[pd.DataFrame, pd.Series] warnings.showwarning = _custom_warning @@ -38,14 +40,18 @@ class PastaStore: name of the PastaStore, by default takes the name of the Connector object """ - def __init__(self, connector, name: str = None): + def __init__( + self, + connector: BaseConnector = DictConnector("pastas_db"), + name: Optional[str] = None, + ): """Initialize PastaStore for managing pastas time series and models. Parameters ---------- - connector : Connector object - object that provides the interface to the - database + connector : Connector object, optional + object that provides the connection to the database. Default is + DictConnector which does not store data on disk. name : str, optional name of the PastaStore, if not provided uses the Connector name """ diff --git a/pastastore/util.py b/pastastore/util.py index 1c28f5a0..313c0396 100644 --- a/pastastore/util.py +++ b/pastastore/util.py @@ -8,7 +8,7 @@ from pastas.stats.tests import runs_test, stoffer_toloi from tqdm.auto import tqdm -from .version import PASTAS_LEQ_022 +from pastastore.version import PASTAS_LEQ_022 def _custom_warning(message, category=UserWarning, filename="", lineno=-1, *args): diff --git a/pastastore/version.py b/pastastore/version.py index 3afd6c04..04980b4f 100644 --- a/pastastore/version.py +++ b/pastastore/version.py @@ -4,4 +4,4 @@ PASTAS_VERSION = parse_version(ps.__version__) PASTAS_LEQ_022 = PASTAS_VERSION <= parse_version("0.22.0") -__version__ = "1.2.2" +__version__ = "1.3.0b" diff --git a/pastastore/yaml_interface.py b/pastastore/yaml_interface.py index 00a28a13..4d07c352 100644 --- a/pastastore/yaml_interface.py +++ b/pastastore/yaml_interface.py @@ -2,14 +2,14 @@ import logging import os from copy import deepcopy -from typing import Dict, List, Optional, Union +from typing import Any, Dict, List, Optional, Union import numpy as np import pandas as pd import pastas as ps import yaml -from .version import PASTAS_LEQ_022 +from pastastore.version import PASTAS_LEQ_022 ps.logger.setLevel("ERROR") @@ -17,7 +17,7 @@ logger = logging.getLogger(__name__) -def _convert_dict_dtypes_for_yaml(d: Dict): +def _convert_dict_dtypes_for_yaml(d: Dict[str, Any]): """Internal method to convert dictionary values for storing in YAML format. Parameters