rwijtvliet / portfolyo

Handling timeseries for power and gas retail portfolios.
BSD 3-Clause "New" or "Revised" License
0 stars 0 forks source link

[enhancement] slicing with right-open interval #61

Closed rwijtvliet closed 6 months ago

rwijtvliet commented 9 months ago

Context

The PfLine and PfState classes have the .loc[] property, which is inherited from pandas. It allows us to select from/until a certain row. E.g., if df is a pandas DataFrame, we can do df.loc['2020':'2022'].

This is inclusive-inclusive, meaning, both the left and the right limit are included in the selection. Let's say df has hourly values:

Problem

This goes contrary to common slicing operations in python, which do not include the endpoint.

It is unpractical too. Let's say we have a price-pfline pfl1 spanning the whole 2020, 2021, and 2022, and pfl2 spanning the whole 2022, 2023 and 2024. And we want to combine them into 1 pfline spanning 2020, 2021, 2022, 2023 and 2024. Here we focus on slicing the portfolio lines so that they have no overlap but also no gap between them. (How we combine them into a new pfline is a different issue.) Let's say we want the split to be so, that everything before 2022 must be from pfl1, and everything during/after 2022 from pfl2. Using .loc[], we must use:

Solution

Add a property (maybe called .slice[]?), which uses the more common slicing convention, where .slice[a:b] includes a but excludes b. The same issue as above then becomes:

Much better.

Notes

Pizza2Pizza commented 6 months ago

merged :)