Skip to content

Commit

Permalink
Merge pull request #296 from awarsewa/master
Browse files Browse the repository at this point in the history
+if clause for _query_imbalance in decorators
  • Loading branch information
fboerman authored Jan 31, 2024
2 parents 3a0e33b + 0b2385c commit ef6f5fc
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 20 deletions.
40 changes: 21 additions & 19 deletions entsoe/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,10 @@ def documents_wrapper(*args, **kwargs):
raise NoMatchingDataError

df = pd.concat(frames, sort=True)
# For same indices pick last valid value
if df.index.has_duplicates:
df = df.groupby(df.index).agg(deduplicate_documents_limited)
if func.__name__ != '_query_unavailability':
# For same indices pick last valid value
if df.index.has_duplicates:
df = df.groupby(df.index).agg(deduplicate_documents_limited)
return df
return documents_wrapper
return decorator
Expand Down Expand Up @@ -121,22 +122,23 @@ def year_wrapper(*args, start=None, end=None, **kwargs):
for _start, _end in blocks:
try:
frame = func(*args, start=_start, end=_end, **kwargs)
# Due to partial matching func may return data indexed by
# timestamps outside _start and _end. In order to avoid
# (unintentionally) repeating records, frames are truncated to
# left-open intervals (or closed interval in the case of the
# earliest block).
#
# If there are repeating records in a single frame (e.g. due
# to corrections) then the result will also have them.
if is_first_frame:
interval_mask = frame.index <= _end
else:
interval_mask = (
(frame.index <= _end)
& (frame.index > _start)
)
frame = frame.loc[interval_mask]
if func.__name__ != '_query_unavailability':
# Due to partial matching func may return data indexed by
# timestamps outside _start and _end. In order to avoid
# (unintentionally) repeating records, frames are truncated to
# left-open intervals (or closed interval in the case of the
# earliest block).
#
# If there are repeating records in a single frame (e.g. due
# to corrections) then the result will also have them.
if is_first_frame:
interval_mask = frame.index <= _end
else:
interval_mask = (
(frame.index <= _end)
& (frame.index > _start)
)
frame = frame.loc[interval_mask]
except NoMatchingDataError:
logger.debug(
f"NoMatchingDataError: between {_start} and {_end}"
Expand Down
4 changes: 3 additions & 1 deletion entsoe/parsers.py
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,9 @@ def _parse_aggregated_bids_timeseries(soup):

for dt, point in zip(tx, points):
df.loc[dt, 'Offered'] = float(point.find('quantity').text)
df.loc[dt, 'Activated'] = float(point.find('secondaryquantity').text)
activated = point.find('secondaryquantity')
if activated is not None:
df.loc[dt, 'Activated'] = float(activated.text)

mr_id = int(soup.find('mrid').text)
df.columns = pd.MultiIndex.from_product(
Expand Down

0 comments on commit ef6f5fc

Please sign in to comment.