Skip to content

Commit

Permalink
created branch concat
Browse files Browse the repository at this point in the history
  • Loading branch information
Alina Voilova committed Feb 13, 2024
1 parent 2aea7ee commit 10d7f55
Show file tree
Hide file tree
Showing 10 changed files with 25 additions and 4 deletions.
21 changes: 21 additions & 0 deletions docs/core/pfline.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
=======================================
Expand Down
4 changes: 2 additions & 2 deletions portfolyo/__init__.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion portfolyo/core/pfline/classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Empty file added portfolyo/core/pfline/concat.py
Empty file.
2 changes: 1 addition & 1 deletion portfolyo/core/pfstate/pfstate.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
File renamed without changes.
Empty file added portfolyo/core/shared/concat.py
Empty file.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit 10d7f55

Please sign in to comment.