From 47e921a266c99a635e664d9551e0e1b4e8c47213 Mon Sep 17 00:00:00 2001 From: rwijtvliet Date: Tue, 16 Apr 2024 11:43:22 +0200 Subject: [PATCH 1/2] initial commit --- docs/core/toplevel.rst | 30 +++++++++ docs/index.rst | 3 +- docs/specialized_topics/resampling.rst | 2 +- poetry.lock | 90 +++++++++++++++++++++++++- portfolyo/__init__.py | 9 +-- pyproject.toml | 1 + 6 files changed, 128 insertions(+), 7 deletions(-) create mode 100644 docs/core/toplevel.rst diff --git a/docs/core/toplevel.rst b/docs/core/toplevel.rst new file mode 100644 index 0000000..4b2c891 --- /dev/null +++ b/docs/core/toplevel.rst @@ -0,0 +1,30 @@ +.. |_| unicode:: 0xA0 + :trim: + +=============== +Top-level tools +=============== + +Some tools for working with ``pandas.Series``, ``pandas.DataFrame``, ``portfolyo.PfLine`` and ``portfolyo.PfState`` objects are available at the root of the package. They are concisely listed below. + +---------------------- +Work on pandas objects +---------------------- + +* ``portfolyo.asfreq_avg()`` Changes the frequency of a Series or DataFrame with "averagable" data. See :doc:`this page<../specialized_topics/resampling>` for more information. + +* ``portfolyo.asfreq_sum()`` Changes the frequency of a Series or DataFrame with "summable" data. See :doc:`this page<../specialized_topics/resampling>` for more information. + +* ``portfolyo.wavg()`` Calculates weighted average of a Series or DataFrame. + +* ``portfolyo.standardize()`` Ensures/asserts a Series or DataFrame follows necessary rules to initialize PfLine with. + +------------------------- +Work on portfolyo objects +------------------------- + +* ``portfolyo.concat()`` Concatenates PfLines into one PfLine. + +* ``portfolyo.plot_pfstates()`` Plots several PfStates in one figure. + + diff --git a/docs/index.rst b/docs/index.rst index f396077..370b62d 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -68,6 +68,7 @@ Contents core/pfline core/pfstate core/interoperability + core/toplevel .. toctree:: :maxdepth: 1 @@ -94,4 +95,4 @@ Contents :maxdepth: 2 :caption: Full reference - full_reference \ No newline at end of file + full_reference diff --git a/docs/specialized_topics/resampling.rst b/docs/specialized_topics/resampling.rst index 86ae88e..63d3b34 100644 --- a/docs/specialized_topics/resampling.rst +++ b/docs/specialized_topics/resampling.rst @@ -137,4 +137,4 @@ The reason for the higher price in the previous example, is that, there, the pri Resampling with ``portfolyo`` ----------------------------- -When changing the frequency of a ``PfLine`` or ``PfState`` object, the considerations above are automatically taken into account. If you are in the situation of having to change the frequency of a ``pandas.Series`` or ``DataFrame`` with a ``DatetimeIndex``, however, the relevant functions are also available at the ``portfolyo.tools.changefreq`` module. +When changing the frequency of a ``PfLine`` or ``PfState`` object, the considerations above are automatically taken into account when using the ``.asfreq()`` method. If you are in the situation of having to change the frequency of a ``pandas.Series`` or ``DataFrame`` with a ``DatetimeIndex``, however, the relevant functions are also available at the package root, as the ``portfolyo.asfreq_avg()`` and ``portfolyo.asfreq_sum()`` functions. diff --git a/poetry.lock b/poetry.lock index 582f065..cb1fdc3 100644 --- a/poetry.lock +++ b/poetry.lock @@ -153,6 +153,31 @@ webencodings = "*" [package.extras] css = ["tinycss2 (>=1.1.0,<1.3)"] +[[package]] +name = "build" +version = "1.2.1" +description = "A simple, correct Python build frontend" +optional = false +python-versions = ">=3.8" +files = [ + {file = "build-1.2.1-py3-none-any.whl", hash = "sha256:75e10f767a433d9a86e50d83f418e83efc18ede923ee5ff7df93b6cb0306c5d4"}, + {file = "build-1.2.1.tar.gz", hash = "sha256:526263f4870c26f26c433545579475377b2b7588b6f1eac76a001e873ae3e19d"}, +] + +[package.dependencies] +colorama = {version = "*", markers = "os_name == \"nt\""} +importlib-metadata = {version = ">=4.6", markers = "python_full_version < \"3.10.2\""} +packaging = ">=19.1" +pyproject_hooks = "*" +tomli = {version = ">=1.1.0", markers = "python_version < \"3.11\""} + +[package.extras] +docs = ["furo (>=2023.08.17)", "sphinx (>=7.0,<8.0)", "sphinx-argparse-cli (>=1.5)", "sphinx-autodoc-typehints (>=1.10)", "sphinx-issues (>=3.0.0)"] +test = ["build[uv,virtualenv]", "filelock (>=3)", "pytest (>=6.2.4)", "pytest-cov (>=2.12)", "pytest-mock (>=2)", "pytest-rerunfailures (>=9.1)", "pytest-xdist (>=1.34)", "setuptools (>=42.0.0)", "setuptools (>=56.0.0)", "setuptools (>=56.0.0)", "setuptools (>=67.8.0)", "wheel (>=0.36.0)"] +typing = ["build[uv]", "importlib-metadata (>=5.1)", "mypy (>=1.9.0,<1.10.0)", "tomli", "typing-extensions (>=3.7.4.3)"] +uv = ["uv (>=0.1.18)"] +virtualenv = ["virtualenv (>=20.0.35)"] + [[package]] name = "certifi" version = "2023.11.17" @@ -1804,6 +1829,41 @@ files = [ [package.extras] test = ["codecov", "coveralls", "nbval", "pyarrow", "pytest", "pytest-cov", "pytest-mpl", "pytest-subtests"] +[[package]] +name = "pip" +version = "24.0" +description = "The PyPA recommended tool for installing Python packages." +optional = false +python-versions = ">=3.7" +files = [ + {file = "pip-24.0-py3-none-any.whl", hash = "sha256:ba0d021a166865d2265246961bec0152ff124de910c5cc39f1156ce3fa7c69dc"}, + {file = "pip-24.0.tar.gz", hash = "sha256:ea9bd1a847e8c5774a5777bb398c19e80bcd4e2aa16a4b301b718fe6f593aba2"}, +] + +[[package]] +name = "pip-tools" +version = "7.4.1" +description = "pip-tools keeps your pinned dependencies fresh." +optional = false +python-versions = ">=3.8" +files = [ + {file = "pip-tools-7.4.1.tar.gz", hash = "sha256:864826f5073864450e24dbeeb85ce3920cdfb09848a3d69ebf537b521f14bcc9"}, + {file = "pip_tools-7.4.1-py3-none-any.whl", hash = "sha256:4c690e5fbae2f21e87843e89c26191f0d9454f362d8acdbd695716493ec8b3a9"}, +] + +[package.dependencies] +build = ">=1.0.0" +click = ">=8" +pip = ">=22.2" +pyproject_hooks = "*" +setuptools = "*" +tomli = {version = "*", markers = "python_version < \"3.11\""} +wheel = "*" + +[package.extras] +coverage = ["covdefaults", "pytest-cov"] +testing = ["flit_core (>=2,<4)", "poetry_core (>=1.0.0)", "pytest (>=7.2.0)", "pytest-rerunfailures", "pytest-xdist", "tomli-w"] + [[package]] name = "platformdirs" version = "3.11.0" @@ -2011,6 +2071,20 @@ files = [ [package.extras] diagrams = ["jinja2", "railroad-diagrams"] +[[package]] +name = "pyproject-hooks" +version = "1.0.0" +description = "Wrappers to call pyproject.toml-based build backend hooks." +optional = false +python-versions = ">=3.7" +files = [ + {file = "pyproject_hooks-1.0.0-py3-none-any.whl", hash = "sha256:283c11acd6b928d2f6a7c73fa0d01cb2bdc5f07c57a2eeb6e83d5e56b97976f8"}, + {file = "pyproject_hooks-1.0.0.tar.gz", hash = "sha256:f271b298b97f5955d53fb12b72c1fb1948c22c1a6b70b315c54cedaca0264ef5"}, +] + +[package.dependencies] +tomli = {version = ">=1.1.0", markers = "python_version < \"3.11\""} + [[package]] name = "pytest" version = "7.4.3" @@ -2853,6 +2927,20 @@ files = [ {file = "webencodings-0.5.1.tar.gz", hash = "sha256:b36a1c245f2d304965eb4e0a82848379241dc04b865afcc4aab16748587e1923"}, ] +[[package]] +name = "wheel" +version = "0.43.0" +description = "A built-package format for Python" +optional = false +python-versions = ">=3.8" +files = [ + {file = "wheel-0.43.0-py3-none-any.whl", hash = "sha256:55c570405f142630c6b9f72fe09d9b67cf1477fcf543ae5b8dcb1f5b7377da81"}, + {file = "wheel-0.43.0.tar.gz", hash = "sha256:465ef92c69fa5c5da2d1cf8ac40559a8c940886afcef87dcf14b9470862f1d85"}, +] + +[package.extras] +test = ["pytest (>=6.0.0)", "setuptools (>=65)"] + [[package]] name = "zipp" version = "3.17.0" @@ -2871,4 +2959,4 @@ testing = ["big-O", "jaraco.functools", "jaraco.itertools", "more-itertools", "p [metadata] lock-version = "2.0" python-versions = "^3.9" -content-hash = "cc0cdc76ab8b5f234e70e625215e81e9936fdf1b69afc7403abd9436ace0f73a" +content-hash = "478bbb0c307ce8375b666790575ff9333f3f054f5f152e5d3c7c4b4166d00378" diff --git a/portfolyo/__init__.py b/portfolyo/__init__.py index a10d888..ff15f14 100644 --- a/portfolyo/__init__.py +++ b/portfolyo/__init__.py @@ -1,7 +1,6 @@ """Package to analyse and manipulate timeseries related to power and gas offtake portfolios.""" - -from . import _version, dev, tools +from . import _version, dev, testing, tools from .core import extendpandas # extend functionalty of pandas from .core import suppresswarnings from .core.mixins.plot import plot_pfstates @@ -9,11 +8,13 @@ from .core.pfstate import PfState from .prices.hedge import hedge from .prices.utils import is_peak_hour +from .tools.changefreq import averagable as asfreq_avg +from .tools.changefreq import summable as asfreq_sum from .tools.changeyear import characterize_index, map_frame_to_year from .tools.freq import FREQUENCIES from .tools.standardize import frame as standardize from .tools.tzone import force_agnostic, force_aware -from .tools.unit import Q_, ureg, Unit +from .tools.unit import Q_, Unit, ureg from .tools.wavg import general as wavg VOLUME = Kind.VOLUME @@ -25,4 +26,4 @@ suppresswarnings.apply() __version__ = _version.get_versions()["version"] -__all__ = ["tools", "dev", "PfLine", "PfState"] +__all__ = ["tools", "dev", "testing", "PfLine", "PfState"] diff --git a/pyproject.toml b/pyproject.toml index d1ad723..f3a7eeb 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -41,6 +41,7 @@ sphinx-rtd-theme = "^1.3.0" insegel = "^1.3.1" nbsphinx = "^0.9.3" pandoc = "^2.3" +pip-tools = "^7.4.1" [tool.poetry.group.dev.dependencies] From 28ef0fe16906b3b14ed2ee6cc6759bf425a1ee7a Mon Sep 17 00:00:00 2001 From: rwijtvliet Date: Tue, 16 Apr 2024 13:55:48 +0200 Subject: [PATCH 2/2] gitignore --- .gitignore | 2 ++ test-output.xml | 1 - 2 files changed, 2 insertions(+), 1 deletion(-) delete mode 100644 test-output.xml diff --git a/.gitignore b/.gitignore index 70db76d..4c73403 100644 --- a/.gitignore +++ b/.gitignore @@ -49,6 +49,7 @@ coverage.xml *.py,cover .hypothesis/ .pytest_cache/ +test-output.xml cover/ # Translations @@ -160,3 +161,4 @@ cython_debug/ .issues/ .DS_Store test.xlsx + diff --git a/test-output.xml b/test-output.xml deleted file mode 100644 index 8667413..0000000 --- a/test-output.xml +++ /dev/null @@ -1 +0,0 @@ -/Users/alina.voilova/miniconda3/envs/env-portfolyo/lib/python3.9/site-packages/pytest/__main__.py -p vscode_pytest --collect-only teststests \ No newline at end of file