From 10d7f55da16af230e4f0271a4371b9938d2bdf65 Mon Sep 17 00:00:00 2001 From: Alina Voilova Date: Tue, 13 Feb 2024 13:21:49 +0100 Subject: [PATCH] created branch concat --- docs/core/pfline.rst | 21 +++++++++++++++++++ portfolyo/__init__.py | 4 ++-- portfolyo/core/pfline/classes.py | 2 +- portfolyo/core/pfline/concat.py | 0 portfolyo/core/pfstate/pfstate.py | 2 +- portfolyo/core/{mixins => shared}/__init__.py | 0 portfolyo/core/shared/concat.py | 0 .../core/{mixins => shared}/excelclipboard.py | 0 portfolyo/core/{mixins => shared}/plot.py | 0 portfolyo/core/{mixins => shared}/text.py | 0 10 files changed, 25 insertions(+), 4 deletions(-) create mode 100644 portfolyo/core/pfline/concat.py rename portfolyo/core/{mixins => shared}/__init__.py (100%) create mode 100644 portfolyo/core/shared/concat.py rename portfolyo/core/{mixins => shared}/excelclipboard.py (100%) rename portfolyo/core/{mixins => shared}/plot.py (100%) rename portfolyo/core/{mixins => shared}/text.py (100%) diff --git a/docs/core/pfline.rst b/docs/core/pfline.rst index 5a6756d..8ea8ca9 100644 --- a/docs/core/pfline.rst +++ b/docs/core/pfline.rst @@ -269,6 +269,27 @@ Another slicing method is implemented with the ``.slice[]`` property. The improv # --- hide: stop --- +Concatenation +============= + +Portfolio lines can be concatenated with the ``portfolio.concat()`` function. This only works if the input portfolio lines have contain compatible information (the same frequency, timezone, start-of-day, kind, etc) and, crucially, their indices are gapless and without overlap. To remove any overlap, use the ``.slice[]`` property. + +.. exec_code:: + + # --- hide: start --- + import portfolyo as pf, pandas as pd + index = pd.date_range('2024', freq='AS', periods=3) + input_df = pd.DataFrame({'w':[200, 220, 300], 'p': [100, 150, 200]}, index) + pfl = pf.PfLine(input_df) + # --- hide: stop --- + # continuation of previous code example + index2 = pd.date_range('2025', freq='AS', periods=3) # 2 years' overlap with pfl + pfl2 = pf.PfLine(pd.DataFrame({'w':[22, 30, 40], 'p': [15, 20, 21]}, index)) + # first two datapoints (until/excl 2026) from pfl, last two datapoints (from/incl 2026) from pfl2 + pf.concat([pfl.slice[:'2026'], pfl2.slice['2026':]]) + # --- hide: start --- + print(pf.concat([pfl.slice[:'2026'], pfl2.slice['2026':]])) + # --- hide: stop --- Volume-only, price-only or revenue-only ======================================= diff --git a/portfolyo/__init__.py b/portfolyo/__init__.py index a10d888..ee785cf 100644 --- a/portfolyo/__init__.py +++ b/portfolyo/__init__.py @@ -1,10 +1,9 @@ """Package to analyse and manipulate timeseries related to power and gas offtake portfolios.""" - from . import _version, dev, tools from .core import extendpandas # extend functionalty of pandas from .core import suppresswarnings -from .core.mixins.plot import plot_pfstates +from .core.shared.plot import plot_pfstates from .core.pfline import Kind, PfLine, Structure, create from .core.pfstate import PfState from .prices.hedge import hedge @@ -15,6 +14,7 @@ from .tools.tzone import force_agnostic, force_aware from .tools.unit import Q_, ureg, Unit from .tools.wavg import general as wavg +from .core.shared.concat import concat VOLUME = Kind.VOLUME PRICE = Kind.PRICE diff --git a/portfolyo/core/pfline/classes.py b/portfolyo/core/pfline/classes.py index a2aa855..740bea2 100644 --- a/portfolyo/core/pfline/classes.py +++ b/portfolyo/core/pfline/classes.py @@ -8,7 +8,7 @@ import pandas as pd from ... import tools -from ..mixins import ExcelClipboardOutput, PfLinePlot, PfLineText +from ..shared import ExcelClipboardOutput, PfLinePlot, PfLineText from ..ndframelike import NDFrameLike from . import ( create, diff --git a/portfolyo/core/pfline/concat.py b/portfolyo/core/pfline/concat.py new file mode 100644 index 0000000..e69de29 diff --git a/portfolyo/core/pfstate/pfstate.py b/portfolyo/core/pfstate/pfstate.py index ed127a4..cd634ac 100644 --- a/portfolyo/core/pfstate/pfstate.py +++ b/portfolyo/core/pfstate/pfstate.py @@ -12,7 +12,7 @@ import pandas as pd from ... import tools -from ..mixins import ExcelClipboardOutput, PfStatePlot, PfStateText +from ..shared import ExcelClipboardOutput, PfStatePlot, PfStateText from ..ndframelike import NDFrameLike from ..pfline import PfLine, create from . import pfstate_helper diff --git a/portfolyo/core/mixins/__init__.py b/portfolyo/core/shared/__init__.py similarity index 100% rename from portfolyo/core/mixins/__init__.py rename to portfolyo/core/shared/__init__.py diff --git a/portfolyo/core/shared/concat.py b/portfolyo/core/shared/concat.py new file mode 100644 index 0000000..e69de29 diff --git a/portfolyo/core/mixins/excelclipboard.py b/portfolyo/core/shared/excelclipboard.py similarity index 100% rename from portfolyo/core/mixins/excelclipboard.py rename to portfolyo/core/shared/excelclipboard.py diff --git a/portfolyo/core/mixins/plot.py b/portfolyo/core/shared/plot.py similarity index 100% rename from portfolyo/core/mixins/plot.py rename to portfolyo/core/shared/plot.py diff --git a/portfolyo/core/mixins/text.py b/portfolyo/core/shared/text.py similarity index 100% rename from portfolyo/core/mixins/text.py rename to portfolyo/core/shared/text.py