From 8f373c1951bb8b3f89c1b38e935d239abc9f6b62 Mon Sep 17 00:00:00 2001 From: Victor Garcia Reolid Date: Thu, 21 Mar 2024 21:38:45 +0100 Subject: [PATCH] add comments Signed-off-by: Victor Garcia Reolid --- .../sensors/func_store/knowledge_horizons.py | 11 ++++++++--- .../sensors/func_store/test_knowledge_horizons.py | 2 +- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/timely_beliefs/sensors/func_store/knowledge_horizons.py b/timely_beliefs/sensors/func_store/knowledge_horizons.py index 608d835b..d333de44 100644 --- a/timely_beliefs/sensors/func_store/knowledge_horizons.py +++ b/timely_beliefs/sensors/func_store/knowledge_horizons.py @@ -55,11 +55,16 @@ def x_years_ago_at_date( These bounds are normally useful for creating more efficient database queries when filtering by belief time. """ - if x < 0: - raise ValueError("Negative value for `x` not supported.") + MAX_DAYS_IN_A_YEAR = 366 + MIN_DAYS_IN_A_YEAR = 366 + + if x <= 0: + raise ValueError("Only positive values for `x` are supported.") if get_bounds: - return timedelta(days=(x - 1) * 366 - 3), timedelta(days=(x + 1) * 366 + 1) + # The minimum corresponds to an event at the 1st of January and a reference on the 31st of December on the the year `x` years ago. + # The maximum correponds to an event on the 31st of December and a reference on the 1st of January on the year `x` years ago. + return timedelta(days=(x - 1) * MIN_DAYS_IN_A_YEAR), timedelta(days=(x + 1) * MAX_DAYS_IN_A_YEAR + 1) if isinstance(event_start, datetime): return x_years_ago_at_date_datetime(event_start, day, month, x, z) diff --git a/timely_beliefs/sensors/func_store/test_knowledge_horizons.py b/timely_beliefs/sensors/func_store/test_knowledge_horizons.py index 67c18441..b62c7cdb 100644 --- a/timely_beliefs/sensors/func_store/test_knowledge_horizons.py +++ b/timely_beliefs/sensors/func_store/test_knowledge_horizons.py @@ -152,7 +152,7 @@ def test_x_years_ago_at_date(): datetime(2024, 12, 31, 23, 59, 59, tzinfo=utc), ], ) -@pytest.mark.parametrize("year", list(range(6))) +@pytest.mark.parametrize("year", list(range(1,6))) def test_x_years_ago_at_date_bounds(event_start, year): knowledge_func_params = dict(month=12, day=31, x=year)