Skip to content

Commit

Permalink
code review suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
sbidari committed Dec 30, 2024
1 parent 73b3128 commit 2f8da43
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
9 changes: 5 additions & 4 deletions pyrenew/convolve.py
Original file line number Diff line number Diff line change
Expand Up @@ -249,16 +249,17 @@ def daily_to_weekly(
with the first full week available.
"""
if input_data_first_dow < 0 or input_data_first_dow > 6:
raise ValueError("First day of the week for input timeseries must be between 0 and 6.")
raise ValueError(
"First day of the week for input timeseries must be between 0 and 6."
)

if week_start_dow < 0 or week_start_dow > 6:
raise ValueError(
"Week start date for output aggregated values must be between 0 and 6."
)

if input_data_first_dow != week_start_dow:
offset = (week_start_dow - input_data_first_dow) % 7
daily_values = daily_values[offset:]
offset = (week_start_dow - input_data_first_dow) % 7
daily_values = daily_values[offset:]

if len(daily_values) < 7:
raise ValueError("No complete weekly values available")
Expand Down
5 changes: 3 additions & 2 deletions test/test_daily_to_weekly.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,14 @@ def test_daily_to_weekly_invalid_offset():
"""
daily_values = jnp.arange(1, 15)
with pytest.raises(
ValueError, match="First day of the week must be between 0 and 6."
ValueError,
match="First day of the week for input timeseries must be between 0 and 6.",
):
daily_to_weekly(daily_values, input_data_first_dow=-1)

with pytest.raises(
ValueError,
match="First day of aggregated data must be between 0 and 6.",
match="Week start date for output aggregated values must be between 0 and 6.",
):
daily_to_weekly(daily_values, week_start_dow=7)

Expand Down

0 comments on commit 2f8da43

Please sign in to comment.