Skip to content

Commit

Permalink
Pass on new timely-beliefs argument most_recent_only (#204)
Browse files Browse the repository at this point in the history
Expose the new optional functionality from SeitaBV/timely-beliefs#76, without deciding where in the FlexMeasures code it makes sense to actually set `most_recent_only=True`.


* Pass on new timely-beliefs argument

* Update parameter documentation
  • Loading branch information
Flix6x committed Oct 7, 2021
1 parent 28dcf1d commit fe10cef
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
6 changes: 6 additions & 0 deletions flexmeasures/data/models/time_series.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ def search_beliefs(
source: Optional[
Union[DataSource, List[DataSource], int, List[int], str, List[str]]
] = None,
most_recent_only: bool = False,
as_json: bool = False,
) -> Union[tb.BeliefsDataFrame, str]:
"""Search all beliefs about events for this sensor.
Expand All @@ -81,6 +82,7 @@ def search_beliefs(
:param beliefs_after: only return beliefs formed after this datetime (inclusive)
:param beliefs_before: only return beliefs formed before this datetime (inclusive)
:param source: search only beliefs by this source (pass the DataSource, or its name or id) or list of sources
:param most_recent_only: only return the most recent beliefs for each event from each source (minimum belief horizon)
:param as_json: return beliefs in JSON format (e.g. for use in charts) rather than as BeliefsDataFrame
:returns: BeliefsDataFrame or JSON string (if as_json is True)
"""
Expand All @@ -91,6 +93,7 @@ def search_beliefs(
beliefs_after=beliefs_after,
beliefs_before=beliefs_before,
source=source,
most_recent_only=most_recent_only,
)
if as_json:
df = bdf.reset_index()
Expand Down Expand Up @@ -219,6 +222,7 @@ def search(
source: Optional[
Union[DataSource, List[DataSource], int, List[int], str, List[str]]
] = None,
most_recent_only: bool = False,
) -> tb.BeliefsDataFrame:
"""Search all beliefs about events for a given sensor.
Expand All @@ -228,6 +232,7 @@ def search(
:param beliefs_after: only return beliefs formed after this datetime (inclusive)
:param beliefs_before: only return beliefs formed before this datetime (inclusive)
:param source: search only beliefs by this source (pass the DataSource, or its name or id) or list of sources
:param most_recent_only: only return the most recent beliefs for each event from each source (minimum belief horizon)
"""
parsed_sources = parse_source_arg(source)
return cls.search_session(
Expand All @@ -238,6 +243,7 @@ def search(
beliefs_after=beliefs_after,
beliefs_before=beliefs_before,
source=parsed_sources,
most_recent_only=most_recent_only,
)

@classmethod
Expand Down
2 changes: 1 addition & 1 deletion requirements/app.in
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ netCDF4
siphon
tables
timetomodel>=0.6.8
timely-beliefs>=1.4.5
timely-beliefs>=1.5.0
python-dotenv
# a backport, not needed in Python3.8
importlib_metadata
Expand Down
2 changes: 1 addition & 1 deletion requirements/app.txt
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ tables==3.6.1
# via -r requirements/app.in
threadpoolctl==2.1.0
# via scikit-learn
timely-beliefs==1.4.5
timely-beliefs==1.5.0
# via -r requirements/app.in
timetomodel==0.6.9
# via -r requirements/app.in
Expand Down

0 comments on commit fe10cef

Please sign in to comment.