Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

'year_limited' is skipping (sometimes?) the first row of the frames leanding to missing row in final results #363

Open
sdementen opened this issue Nov 13, 2024 · 1 comment

Comments

@sdementen
Copy link

sdementen commented Nov 13, 2024

To reproduce the bug

import pandas
from entsoe import EntsoePandasClient

client = EntsoePandasClient(api_key="397870bf-afdc-4422-ba9e-2d8ef803fa2a")  # API key from Sebastien de Menten (GFJ138), use with care
client.session.verify = False
df = client.query_day_ahead_prices("FR", start=pandas.Timestamp("2022", tz="CET"), end=pandas.Timestamp("2023/02", tz="CET"))
print(df["2022-12-30T22":"2022-12-31T02"])

outputs

2022-12-30 22:00:00+01:00    4.11
2022-12-30 23:00:00+01:00    4.11
2022-12-31 01:00:00+01:00    0.13
2022-12-31 02:00:00+01:00    0.06

where we are missing 2022-12-31 00:00:00+01:00

This is due to the filter https://github.com/EnergieID/entsoe-py/blob/master/entsoe/decorators.py#L139 which may skip the first row of the second and subsequent queries.
This could be replaced by the following that explicitly filter index that would overlap with the previous frame

                        interval_mask = (
                            (frame.index <= _end)
                            & (frame.index > frames[-1].index[-1])
                        )

entsoe.version == "0.6.16"

@Tijoxa
Copy link

Tijoxa commented Nov 15, 2024

To clarify, the year_limited decorator tries to enforce the _start and _end timestamps to the result frame. However other side effects can happen:

To reproduce the bug

import pandas
from entsoe import EntsoePandasClient

client = EntsoePandasClient(api_key="397870bf-afdc-4422-ba9e-2d8ef803fa2a")  # API key from Sebastien de Menten (GFJ138), use with care
client.session.verify = False
df = client.query_installed_generation_capacity(
    "FR",
    start=pd.Timestamp("2017-01-01", tz="Europe/Paris"),
    end=pd.Timestamp("2023-01-01", tz="Europe/Paris"),
)
print(df.index)

outputs

DatetimeIndex(['2017-01-01 00:00:00+01:00'], dtype='datetime64[ns, Europe/Paris]', freq=None)

This is due to the fact that for the first block, the api returns a single row of date '2017-01-01 00:00:00+01:00' and the decorator doesn't filter out this value since it's the first frame.
But for the following ones the api returns the first timestamp of each year ('2018-01-01 00:00:00+01:00', '2019-01-01 00:00:00+01:00', …). But those values are filtered out by the condition frame.index > _start.

You're solution handles that well too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants