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

Fix: incompatible criteria for most_recent_events_only #175

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 7 additions & 8 deletions timely_beliefs/beliefs/classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -488,13 +488,10 @@ def apply_belief_timing_filters(q):
q = q.join(source_class).filter(cls.source_id.in_([s.id for s in sources]))

# Apply most recent beliefs filter as subquery
most_recent_beliefs_only_incompatible_criteria = (
most_recent_only_incompatible_criteria = (
beliefs_before is not None or beliefs_after is not None
) and sensor.knowledge_horizon_fnc not in (ex_ante.__name__, ex_post.__name__)
if (
most_recent_beliefs_only
and not most_recent_beliefs_only_incompatible_criteria
):
if most_recent_beliefs_only and not most_recent_only_incompatible_criteria:
subq = select(
cls.event_start,
cls.source_id,
Expand All @@ -519,7 +516,7 @@ def apply_belief_timing_filters(q):
)

# Apply most recent events filter as subquery
if most_recent_events_only:
if most_recent_events_only and not most_recent_only_incompatible_criteria:
subq_most_recent_events = select(
cls.source_id,
func.max(cls.event_start).label("most_recent_event_start"),
Expand Down Expand Up @@ -576,8 +573,10 @@ def apply_belief_timing_filters(q):
if beliefs_before is not None:
df = df[df.index.get_level_values("belief_time") <= beliefs_before]

# Select most recent beliefs using postprocessing in case of incompatible search criteria
if most_recent_beliefs_only and most_recent_beliefs_only_incompatible_criteria:
# Select most recent events/beliefs using postprocessing in case of incompatible search criteria
if most_recent_events_only and most_recent_only_incompatible_criteria:
df = df[df.index.get_level_values("event_start") == df.event_starts.max()]
if most_recent_beliefs_only and most_recent_only_incompatible_criteria:
df = belief_utils.select_most_recent_belief(df)

# Convert timezone of beliefs and events to sensor timezone
Expand Down
Loading