Skip to content

Commit

Permalink
day ahead prices is now more restricted. enable document_limited and …
Browse files Browse the repository at this point in the history
…make sure the fix by extending days does not interfer. fixes #350
  • Loading branch information
fboerman committed Oct 16, 2024
1 parent 033dcb5 commit 5e9f4c6
Showing 1 changed file with 31 additions and 12 deletions.
43 changes: 31 additions & 12 deletions entsoe/entsoe.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
warnings.filterwarnings('ignore', category=XMLParsedAsHTMLWarning)

__title__ = "entsoe-py"
__version__ = "0.6.11"
__version__ = "0.6.12"
__author__ = "EnergieID.be, Frank Boerman"
__license__ = "MIT"

Expand Down Expand Up @@ -156,7 +156,8 @@ def _datetime_to_str(dtm: pd.Timestamp) -> str:
return ret_str

def query_day_ahead_prices(self, country_code: Union[Area, str],
start: pd.Timestamp, end: pd.Timestamp) -> str:
start: pd.Timestamp, end: pd.Timestamp,
offset: int = 0) -> str:
"""
Parameters
----------
Expand All @@ -172,7 +173,8 @@ def query_day_ahead_prices(self, country_code: Union[Area, str],
params = {
'documentType': 'A44',
'in_Domain': area.code,
'out_Domain': area.code
'out_Domain': area.code,
'offset': offset
}
response = self._base_request(params=params, start=start, end=end)
return response.text
Expand Down Expand Up @@ -1199,8 +1201,8 @@ def query_aggregated_bids(self, country_code: Union[Area, str],
df = df.tz_convert(area.tz)
df = df.truncate(before=start, after=end)
return df
@year_limited

# we need to do offset, but we also want to pad the days so wrap it in an internal call
def query_day_ahead_prices(
self, country_code: Union[Area, str],
start: pd.Timestamp,
Expand All @@ -1223,21 +1225,38 @@ def query_day_ahead_prices(
raise InvalidParameterError('Please choose either 60min, 30min or 15min')
area = lookup_area(country_code)
# we do here extra days at start and end to fix issue 187
text = super(EntsoePandasClient, self).query_day_ahead_prices(
country_code=area,
series = self._query_day_ahead_prices(
area,
start=start-pd.Timedelta(days=1),
end=end+pd.Timedelta(days=1)
end=end+pd.Timedelta(days=1),
resolution=resolution
)
series = parse_prices(text)[resolution]
if len(series) == 0:
raise NoMatchingDataError
series = series.tz_convert(area.tz)
series = series.truncate(before=start, after=end)
# because of the above fix we need to check again if any valid data exists after truncating
if len(series) == 0:
raise NoMatchingDataError
return series

@year_limited
@documents_limited(100)
def _query_day_ahead_prices(
self, area: Area,
start: pd.Timestamp,
end: pd.Timestamp,
resolution: Literal['60min', '30min', '15min'] = '60min',
offset: int = 0) -> pd.Series:
text = super(EntsoePandasClient, self).query_day_ahead_prices(
area,
start=start,
end=end,
offset=offset
)
series = parse_prices(text)[resolution]

if len(series) == 0:
raise NoMatchingDataError
return series

@year_limited
def query_load(self, country_code: Union[Area, str], start: pd.Timestamp,
end: pd.Timestamp) -> pd.DataFrame:
Expand Down

0 comments on commit 5e9f4c6

Please sign in to comment.