Skip to content

Commit

Permalink
Make right truncation offset in forecast data None rather than 0 (#305)
Browse files Browse the repository at this point in the history
  • Loading branch information
dylanhmorris authored Jan 23, 2025
1 parent 6180684 commit d890014
Show file tree
Hide file tree
Showing 4 changed files with 103 additions and 2 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ readme = "README.md"

[tool.poetry.dependencies]
python = "^3.12"
pyrenew = {git = "https://github.com/CDCgov/PyRenew"}
pyrenew = {git = "https://github.com/cdcgov/pyrenew"}
ipywidgets = "^8.1.5"
arviz = "^0.20.0"
pyyaml = "^6.0.2"
Expand Down
3 changes: 2 additions & 1 deletion pyrenew_hew/pyrenew_hew_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,5 +169,6 @@ def to_forecast_data(self, n_forecast_points: int) -> Self:
first_ed_visits_date=self.first_data_date_overall,
first_hospital_admissions_date=(self.first_data_date_overall),
first_wastewater_date=self.first_data_date_overall,
right_truncation_offset=0,
right_truncation_offset=None,
# by default, want forecasts of complete reports
)
File renamed without changes.
100 changes: 100 additions & 0 deletions tests/test_pyrenew_hew_data.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
from datetime import datetime

import pytest

from pyrenew_hew.pyrenew_hew_data import PyrenewHEWData


@pytest.mark.parametrize(
[
"n_ed_visits_datapoints",
"n_hospital_admissions_datapoints",
"n_wastewater_datapoints",
"right_truncation_offset",
"first_ed_visits_date",
"first_hospital_admissions_date",
"first_wastewater_date",
"n_forecast_points",
],
[
[
50,
0,
0,
5,
datetime(2023, 1, 1),
datetime(2022, 2, 5),
datetime(2025, 12, 5),
10,
],
[
0,
325,
2,
5,
datetime(2025, 1, 1),
datetime(2023, 5, 25),
datetime(2022, 4, 5),
10,
],
[
0,
0,
2,
3,
datetime(2025, 1, 1),
datetime(2025, 2, 5),
datetime(2024, 12, 5),
30,
],
[
0,
0,
23,
3,
datetime(2025, 1, 1),
datetime(2025, 2, 5),
datetime(2024, 12, 5),
30,
],
],
)
def test_to_forecast_data(
n_ed_visits_datapoints: int,
n_hospital_admissions_datapoints: int,
n_wastewater_datapoints: int,
right_truncation_offset: int,
first_ed_visits_date: datetime.date,
first_hospital_admissions_date: datetime.date,
first_wastewater_date: datetime.date,
n_forecast_points: int,
) -> None:
"""
Test the to_forecast_data method
"""
data = PyrenewHEWData(
n_ed_visits_datapoints=n_ed_visits_datapoints,
n_hospital_admissions_datapoints=n_hospital_admissions_datapoints,
n_wastewater_datapoints=n_wastewater_datapoints,
first_ed_visits_date=first_ed_visits_date,
first_hospital_admissions_date=first_hospital_admissions_date,
first_wastewater_date=first_wastewater_date,
right_truncation_offset=right_truncation_offset,
)

assert data.right_truncation_offset == right_truncation_offset
assert data.right_truncation_offset is not None

forecast_data = data.to_forecast_data(n_forecast_points)
n_days_expected = data.n_days_post_init + n_forecast_points
n_weeks_expected = n_days_expected // 7
assert forecast_data.n_ed_visits_datapoints == n_days_expected
assert forecast_data.n_wastewater_datapoints == n_days_expected
assert forecast_data.n_hospital_admissions_datapoints == n_weeks_expected
assert forecast_data.right_truncation_offset is None
assert forecast_data.first_ed_visits_date == data.first_data_date_overall
assert (
forecast_data.first_hospital_admissions_date
== data.first_data_date_overall
)
assert forecast_data.first_wastewater_date == data.first_data_date_overall

0 comments on commit d890014

Please sign in to comment.