Skip to content

Commit

Permalink
merged develop
Browse files Browse the repository at this point in the history
  • Loading branch information
rwijtvliet committed Aug 16, 2024
1 parent dfebb52 commit c3e069d
Show file tree
Hide file tree
Showing 78 changed files with 2,576 additions and 2,431 deletions.
5 changes: 4 additions & 1 deletion .github/workflows/ci-on-pullreq.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ on: [pull_request]
jobs:
test:
runs-on: ${{ matrix.os }}
env:
MPLBACKEND: Agg
strategy:
fail-fast: false
matrix:
Expand All @@ -23,8 +25,9 @@ jobs:
with:
python-version: ${{ matrix.python-version }}
architecture: x64


- name: Install
- name: Install poetry
run: |
pip install poetry
poetry install --with dev,test
Expand Down
4 changes: 2 additions & 2 deletions benchmark/benchmark.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def sizeof(o):

def benchmark_pfline(df):
for le, ru in tqdm.tqdm(zip(LENGTHS, RUNS)):
i = pd.date_range("2020", periods=le, freq="15T")
i = pd.date_range("2020", periods=le, freq="15min")
for cols in ["q", "p", "qr", "wp"]:
print(f"{le=} {cols=}")
data = pd.DataFrame({c: np.linspace(1, 1000, le) for c in cols}, i)
Expand Down Expand Up @@ -99,7 +99,7 @@ def benchmark_pfline(df):
def benchmark_pfstate(df):
for le, ru in tqdm.tqdm(zip(LENGTHS, RUNS)):
print(f"{le=}")
i = pd.date_range("2020", periods=le, freq="15T")
i = pd.date_range("2020", periods=le, freq="15min")
w_offtake = pf.dev.w_offtake(i)
offtake = pf.PfLine(w_offtake)
unsourced = pf.PfLine(pf.dev.p_marketprices(i))
Expand Down
14 changes: 7 additions & 7 deletions docs/core/interoperability.rst
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ In the code examples below, the following imports are assumed and variables are

import portfolyo as pf
import pandas as pd
idx = pd.date_range("2023", freq="AS", periods=2)
idx = pd.date_range("2023", freq="YS", periods=2)

---------
One value
Expand Down Expand Up @@ -82,7 +82,7 @@ For timeseries, ``pandas.Series`` are used. These can be "unit-agnostic" (i.e.,
# --- hide: start ---
import portfolyo as pf
import pandas as pd
idx = pd.date_range("2023", freq="AS", periods=2)
idx = pd.date_range("2023", freq="YS", periods=2)
# --- hide: stop ---
pd.Series([50, 56.0], idx, dtype="pint[Eur/MWh]") # unit-aware
# --- hide: start ---
Expand All @@ -103,7 +103,7 @@ To pass several timeseries, we can use:
# --- hide: start ---
import portfolyo as pf
import pandas as pd
idx = pd.date_range("2023", freq="AS", periods=2)
idx = pd.date_range("2023", freq="YS", periods=2)
# --- hide: stop ---
{"p": pd.Series([50, 56], idx), "w": pd.Series([120, 125], idx, dtype="pint[MW]")}
# --- hide: start ---
Expand All @@ -118,7 +118,7 @@ To pass several timeseries, we can use:
# --- hide: start ---
import portfolyo as pf
import pandas as pd
idx = pd.date_range("2023", freq="AS", periods=2)
idx = pd.date_range("2023", freq="YS", periods=2)
# --- hide: stop ---
pd.DataFrame({"p": [50, 56], "w": [120, 125]}, idx)
# --- hide: start ---
Expand All @@ -139,7 +139,7 @@ Dictionaries are the most versatily of these objects. They can be used to pass a
# --- hide: start ---
import portfolyo as pf
import pandas as pd
idx = pd.date_range("2023", freq="AS", periods=2)
idx = pd.date_range("2023", freq="YS", periods=2)
# --- hide: stop ---
d1 = {"p": 50}
d2 = {"p": 50, "w": 120}
Expand Down Expand Up @@ -194,7 +194,7 @@ Footnotes
.. code-block:: python
:emphasize-lines: 3,4
>>> idx = pandas.date_range("2023", freq="AS", periods=2)
>>> idx = pandas.date_range("2023", freq="YS", periods=2)
>>> s_agn = pandas.Series([50, 56], idx) # unit-agnostic
>>> s1 = s_agn.astype("pint[Eur/MWh]") # unit-aware
Expand All @@ -212,7 +212,7 @@ Footnotes
.. code-block:: python
:emphasize-lines: 4, 7
>>> idx = pandas.date_range("2023", freq="AS", periods=2)
>>> idx = pandas.date_range("2023", freq="YS", periods=2)
>>> s_price = pandas.Series([50, 56], idx, dtype="pint[Eur/MWh]")
>>> s_volume = pandas.Series([120, 125], idx, dtype="pint[MW]")
>>> df1 = pandas.DataFrame({"p": s_price, "w": s_volume})
Expand Down
38 changes: 19 additions & 19 deletions docs/core/pfline.rst
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ The keys (or dataframe column names) must each be one of the following: ``w`` (p

import portfolyo as pf
import pandas as pd
index = pd.date_range('2024', freq='AS', periods=3)
index = pd.date_range('2024', freq='YS', periods=3)
input_dict = {'w': pd.Series([200, 220, 300.0], index)}
pf.PfLine(input_dict)
# --- hide: start ---
Expand All @@ -95,7 +95,7 @@ Under the condition that a valid ``pint`` unit is present, we may also provide a

# --- hide: start ---
import portfolyo as pf, pandas as pd
index = pd.date_range('2024', freq='AS', periods=3)
index = pd.date_range('2024', freq='YS', periods=3)
# --- hide: stop ---
# using the imports and index from the previous example
input_series = pd.Series([10, 11.5, 10.8], index, dtype='pint[ctEur/kWh]')
Expand All @@ -115,7 +115,7 @@ The keys are used as the children names:

# --- hide: start ---
import portfolyo as pf, pandas as pd
index = pd.date_range('2024', freq='AS', periods=3)
index = pd.date_range('2024', freq='YS', periods=3)
# --- hide: stop ---
pfl1 = pf.PfLine(pd.Series([0.2, 0.22, 0.3], index, dtype='pint[GW]'))
pfl2 = pf.PfLine(pd.Series([100, 150, 200.0], index, dtype='pint[MW]'))
Expand Down Expand Up @@ -177,7 +177,7 @@ The properties ``PfLine.w``, ``.q``, ``.p`` and ``.r`` always return the informa
# --- hide: start ---
# --- hide: stop ---
import portfolyo as pf, pandas as pd
index = pd.date_range('2024', freq='AS', periods=3)
index = pd.date_range('2024', freq='YS', periods=3)
input_df = pd.DataFrame({'w':[200, 220, 300], 'p': [100, 150, 200]}, index)
pfl = pf.PfLine(input_df)

Expand All @@ -198,7 +198,7 @@ If we want to extract more than one timeseries, we can use the ``.df`` attribute

# --- hide: start ---
import portfolyo as pf, pandas as pd
index = pd.date_range('2024', freq='AS', periods=3)
index = pd.date_range('2024', freq='YS', periods=3)
input_df = pd.DataFrame({'w':[200, 220, 300], 'p': [100, 150, 200]}, index)
pfl = pf.PfLine(input_df)
# --- hide: stop ---
Expand All @@ -221,7 +221,7 @@ The ``PfLine.index`` property returns the ``pandas.DatetimeIndex`` that applies

# --- hide: start ---
import portfolyo as pf, pandas as pd
index = pd.date_range('2024', freq='AS', periods=3)
index = pd.date_range('2024', freq='YS', periods=3)
input_df = pd.DataFrame({'w':[200, 220, 300], 'p': [100, 150, 200]}, index)
pfl = pf.PfLine(input_df)
# --- hide: stop ---
Expand All @@ -236,7 +236,7 @@ For convenience, ``portfolyo`` adds a ``.duration`` and a ``right`` property to

# --- hide: start ---
import portfolyo as pf, pandas as pd
index = pd.date_range('2024', freq='AS', periods=3)
index = pd.date_range('2024', freq='YS', periods=3)
input_df = pd.DataFrame({'w':[200, 220, 300], 'p': [100, 150, 200]}, index)
pfl = pf.PfLine(input_df)
# --- hide: stop ---
Expand All @@ -258,7 +258,7 @@ Another slicing method is implemented with the ``.slice[]`` property. The improv

# --- hide: start ---
import portfolyo as pf, pandas as pd
index = pd.date_range('2024', freq='AS', periods=3)
index = pd.date_range('2024', freq='YS', periods=3)
input_df = pd.DataFrame({'w':[200, 220, 300], 'p': [100, 150, 200]}, index)
pfl = pf.PfLine(input_df)
# --- hide: stop ---
Expand All @@ -280,12 +280,12 @@ Portfolio lines can be concatenated with the ``portfolio.concat()`` function. Th

# --- hide: start ---
import portfolyo as pf, pandas as pd
index = pd.date_range('2024', freq='AS', periods=3)
index = pd.date_range('2024', freq='YS', 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
index2 = pd.date_range('2025', freq='YS', 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':]])
Expand Down Expand Up @@ -316,7 +316,7 @@ The data can be shown graphically with the ``.plot()`` method:

# --- hide: start ---
import portfolyo as pf, pandas as pd
index = pd.date_range('2024', freq='AS', periods=3)
index = pd.date_range('2024', freq='YS', periods=3)
pfl = pf.PfLine(pd.DataFrame({'w':[200, 220, 300], 'p': [100, 150, 200]}, index))
# --- hide: stop ---
# continuation of previous code example
Expand Down Expand Up @@ -352,7 +352,7 @@ Using the ``.asfreq()`` method, we can quickly and correctly downsample our data

# --- hide: start ---
import portfolyo as pf, pandas as pd
index = pd.date_range('2024', freq='AS', periods=3)
index = pd.date_range('2024', freq='YS', periods=3)
pfl = pf.PfLine(pd.DataFrame({'w':[200, 220, 300], 'p': [100, 150, 200]}, index))
# --- hide: stop ---
# continuation of previous code example
Expand Down Expand Up @@ -380,7 +380,7 @@ General remarks:
.. exec_code::

import portfolyo as pf, pandas as pd
index = pd.date_range('2024', freq='AS', periods=3)
index = pd.date_range('2024', freq='YS', periods=3)
pfl = pf.PfLine(pd.Series([2, 2.2, 3], index, dtype='pint[MW]'))
pfl_1 = pfl + {'q': 50.0} # standard unit (here: MWh) is assumed
pfl_2 = pfl + pf.Q_(50000.0, 'kWh')
Expand Down Expand Up @@ -435,7 +435,7 @@ Here are several examples.
.. exec_code::

import portfolyo as pf, pandas as pd
index = pd.date_range('2024', freq='AS', periods=3)
index = pd.date_range('2024', freq='YS', periods=3)
vol = pf.PfLine(pd.Series([4, 4.6, 3], index, dtype='pint[MW]'))
vol + pf.Q_(10.0, 'GWh')
# --- hide: start ---
Expand All @@ -447,7 +447,7 @@ Here are several examples.

# --- hide: start ---
import portfolyo as pf, pandas as pd
index = pd.date_range('2024', freq='AS', periods=3)
index = pd.date_range('2024', freq='YS', periods=3)
# --- hide: stop ---
# continuation of previous code example
vol_2 = pf.PfLine({
Expand All @@ -474,7 +474,7 @@ Here are several examples.

# --- hide: start ---
import portfolyo as pf, pandas as pd
index = pd.date_range('2024', freq='AS', periods=3)
index = pd.date_range('2024', freq='YS', periods=3)
vol = pf.PfLine(pd.Series([4, 4.6, 3], index, dtype='pint[MW]'))
vol_2 = pf.PfLine({
'A': pd.Series([4, 4.6, 3], index, dtype='pint[MW]'),
Expand All @@ -492,7 +492,7 @@ Here are several examples.

# --- hide: start ---
import portfolyo as pf, pandas as pd
index = pd.date_range('2024', freq='AS', periods=3)
index = pd.date_range('2024', freq='YS', periods=3)
vol = pf.PfLine(pd.Series([4, 4.6, 3], index, dtype='pint[MW]'))
vol_2 = pf.PfLine({
'A': pd.Series([4, 4.6, 3], index, dtype='pint[MW]'),
Expand Down Expand Up @@ -737,7 +737,7 @@ Using the ``.hedge_with()`` method, the volume timeseries in a portfolio line is
.. exec_code::

import portfolyo as pf, pandas as pd
index = pd.date_range('2024-04-01', '2024-06-01', freq='H', inclusive='left')
index = pd.date_range('2024-04-01', '2024-06-01', freq='h', inclusive='left')
offtake = pf.PfLine(pf.dev.w_offtake(index)) # mock offtake volumes
prices = pf.PfLine(pf.dev.p_marketprices(index)) # mock market prices
# Create hedge
Expand All @@ -764,7 +764,7 @@ For markets that have a concept of "peak" and "offpeak" periods, the ``.po()`` m

# --- hide: start ---
import portfolyo as pf, pandas as pd
index = pd.date_range('2024-04-01', '2024-06-01', freq='H', inclusive='left')
index = pd.date_range('2024-04-01', '2024-06-01', freq='h', inclusive='left')
offtake = pf.PfLine(pf.dev.w_offtake(index)) # mock offtake volumes
# --- hide: stop ---
# continuation of previous code example
Expand Down
Binary file modified docs/savefig/fig_hedge.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/savefig/fig_offtake.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/savefig/fig_plot_pfl.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/savefig/fig_plot_pfs.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 3 additions & 3 deletions docs/specialized_topics/dataprep.rst
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,12 @@ Frequency

The index must have a frequency (``fr.index.freq``) and it must be a valid frequency. To check validity of the frequency, one may use ``portfolyo.assert_freq_valid()``. The following abbreviations are used by ``pandas`` and throughout this package:

* ``15T``: quarterhourly;
* ``H``: hourly;
* ``15min``: quarterhourly;
* ``h``: hourly;
* ``D``: daily;
* ``MS``: monthly;
* ``QS``: quarterly. Also allowed ``QS-FEB``, ``QS-MAR``, etc.;
* ``AS``: yearly. Also allowed ``AS-FEB``, ``AS-MAR``, etc.
* ``YS``: yearly. Also allowed ``YS-FEB``, ``YS-MAR``, etc.

If the frequency is not set, we can try to make pandas infer it:

Expand Down
2 changes: 1 addition & 1 deletion docs/specialized_topics/indices.rst
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ However, when handling timeseries with shorter-than-daily indices, the offset ca

# --- hide: start ---
import pandas as pd
i = pd.date_range('2024-01-05 06:00', freq= 'H', periods = 40)
i = pd.date_range('2024-01-05 06:00', freq= 'h', periods = 40)
print(repr(i))

It contains 40 hourly values, i.e., it does not contain an integer number of days. We cannot infer, how a day is defined, and in these situations it is therefore assumed, that it is the offset of the first timestamp - '06:00' in this case.
Expand Down
2 changes: 1 addition & 1 deletion docs/tutorial/part1.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@
"source": [
"(``portfolyo`` ensures that the values are aggregated correctly. In this case, the price (``p``) values are weighted-averaged (weighted with the duration of each datapoint - in this case a uniform 24h). See [Resampling](../specialized_topics/resampling.rst) for more information.)\n",
"\n",
"The argument ``\"QS\"`` specifies that we want quarterly values starting from January (same as ``\"QS-JAN\"``). The allowed values, in increasing duration, are following: ``\"15T\"`` (=quarterhourly), ``\"H\"`` (=hourly), ``\"D\"`` (=daily), ``\"MS\"`` (=monthly), ``\"QS\"`` (=quarterly, or ``\"QS-FEB\"``, ``\"QS-MAR\"``, etc.), or ``\"AS\"`` (=yearly, or ``\"AS-FEB\"``, ``\"AS-MAR\"``, etc.).\n"
"The argument ``\"QS\"`` specifies that we want quarterly values starting from January (same as ``\"QS-JAN\"``). The allowed values, in increasing duration, are following: ``\"15min\"`` (=quarterhourly), ``\"h\"`` (=hourly), ``\"D\"`` (=daily), ``\"MS\"`` (=monthly), ``\"QS\"`` (=quarterly, or ``\"QS-FEB\"``, ``\"QS-MAR\"``, etc.), or ``\"YS\"`` (=yearly, or ``\"YS-FEB\"``, ``\"YS-MAR\"``, etc.).\n"
]
},
{
Expand Down
Loading

0 comments on commit c3e069d

Please sign in to comment.