Skip to content

Fix date-dimension mismatch in forecast_infections#1324

Merged
sbfnk merged 2 commits intomainfrom
fix-forecast-infections-dates
Mar 9, 2026
Merged

Fix date-dimension mismatch in forecast_infections#1324
sbfnk merged 2 commits intomainfrom
fix-forecast-infections-dates

Conversation

@sbfnk-bot
Copy link
Collaborator

@sbfnk-bot sbfnk-bot commented Mar 5, 2026

Description

This PR closes #1318.

Fixed a bug in forecast_infections() where calling summary() after modifying estimates$args caused a date-dimension mismatch when extending the R trajectory beyond the original observation period. The fix moves the summary() call to before the args modification block.

Initial submission checklist

  • My PR is based on a package issue and I have explicitly linked it.
  • I have tested my changes locally (using devtools::test() and devtools::check()).
  • I have added or updated unit tests where necessary.
  • I have updated the documentation if required and rebuilt docs if yes (using devtools::document()).
  • I have followed the established coding standards (and checked using lintr::lint_package()).
  • I have added a news item linked to this PR.

After the initial Pull Request

  • I have reviewed Checks for this PR and addressed any issues as far as I am able.

Summary by CodeRabbit

  • Bug Fixes
    • Fixed a date-dimension mismatch that occurred when extending forecasts beyond the original observation period. The correction ensures date calculations use the original fit dimensions rather than modified parameters, eliminating alignment issues in extended forecast trajectories and improving forecast reliability.

Move summary() call before args modification to ensure dates are
calculated from the original fit dimensions rather than extended
dimensions. This fixes the error when extending R trajectory beyond
the original observation period.

Co-Authored-By: Sebastian Funk <sebastian.funk@lshtm.ac.uk>
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 5, 2026

Important

Review skipped

Auto incremental reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: bd339be1-0b7c-4f93-abc3-c453ceb4090b

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

Walkthrough

This PR addresses a date-dimension mismatch bug in forecast_infections() where dates were calculated using modified arguments instead of original fit dimensions. The fix involves moving the summary parameter computation to an earlier stage in simulate_infections.R, prior to time-related argument adjustments, ensuring dates align correctly with extracted parameters.

Changes

Cohort / File(s) Summary
Documentation Update
NEWS.md
Adds bug fixes section documenting the resolution of a date-dimension mismatch in forecast_infections() where the summary call used modified arguments instead of original fit dimensions.
Parameter Summary Ordering
R/simulate_infections.R
Relocates the computation of summary(estimates, type = "parameters") to execute before time-related arguments are redefined, ensuring dates extraction occurs with the correct parameter dimensions and preventing length mismatches.

Possibly related PRs

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'Fix date-dimension mismatch in forecast_infections' directly and accurately summarises the main change: fixing a specific bug in the forecast_infections function.
Linked Issues check ✅ Passed The pull request addresses the date-dimension mismatch issue by moving summary() computation before args modification in R/simulate_infections.R, ensuring dates are calculated from original fit dimensions as required by issue #1318.
Out of Scope Changes check ✅ Passed All changes are directly scoped to fixing the date-dimension mismatch: NEWS.md documents the bug fix and R/simulate_infections.R implements the fix by repositioning the summary() call.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix-forecast-infections-dates

Tip

Try Coding Plans. Let us write the prompt for your AI agent so you can ship faster (with fewer bugs).
Share your feedback on Discord.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
NEWS.md (1)

5-5: Start the entry with the action verb "Fixed" per repository conventions.

The coding guidelines require NEWS.md entries to start with action verbs ('Added', 'Fixed', 'Updated', 'Changed'). Consider rephrasing for consistency with other entries in the file.

📝 Suggested rewording
-- A bug was fixed in `forecast_infections()` where the summary call to extract dates was using modified args instead of the original fit dimensions, causing a date-dimension mismatch when extending the R trajectory beyond the original observation period.
+- Fixed a bug in `forecast_infections()` where the summary call to extract dates was using modified args instead of the original fit dimensions, causing a date-dimension mismatch when extending the R trajectory beyond the original observation period.

As per coding guidelines: "Start with action verbs: 'Added', 'Fixed', 'Updated', 'Changed'"

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@NEWS.md` at line 5, Update the NEWS.md entry to begin with the action verb
"Fixed" to match repository conventions: rephrase the line so it starts "Fixed"
and then describes the bug in forecast_infections(), e.g. "Fixed a bug in
forecast_infections() where the summary call to extract dates used modified args
instead of the original fit dimensions, causing a date-dimension mismatch when
extending the R trajectory beyond the original observation period." Ensure the
entry references forecast_infections() and retains the same technical detail.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@NEWS.md`:
- Line 5: Update the NEWS.md entry to begin with the action verb "Fixed" to
match repository conventions: rephrase the line so it starts "Fixed" and then
describes the bug in forecast_infections(), e.g. "Fixed a bug in
forecast_infections() where the summary call to extract dates used modified args
instead of the original fit dimensions, causing a date-dimension mismatch when
extending the R trajectory beyond the original observation period." Ensure the
entry references forecast_infections() and retains the same technical detail.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 62d2d82d-161b-4d93-aa66-d242ae0ebe8b

📥 Commits

Reviewing files that changed from the base of the PR and between 8454b07 and 26128fb.

📒 Files selected for processing (2)
  • NEWS.md
  • R/simulate_infections.R

@sbfnk-bot
Copy link
Collaborator Author

@coderabbitai review

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 5, 2026

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

sbfnk
sbfnk previously approved these changes Mar 6, 2026
@sbfnk sbfnk enabled auto-merge March 6, 2026 16:13
@sbfnk sbfnk requested a review from seabbs March 6, 2026 16:13
Copy link
Contributor

@seabbs seabbs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There needs to be evidence that this works. I suggest adding a unit test that would fail on main and now passes that replicates the usage in the synthetic example case. It would be nice to run the synthetic generator here as well (or show evidence if this was done)

- Fix NEWS.md to start with action verb "Fixed"
- Add unit test for extended R trajectory scenario

Co-Authored-By: Sebastian Funk <sebastian.funk@lshtm.ac.uk>
@sbfnk-bot
Copy link
Collaborator Author

Thanks for the review! I've addressed the feedback:

  1. Fixed NEWS.md to start with "Fixed" per coding guidelines
  2. Added a unit test (test-forecast-infections.R) that replicates the failing scenario - extending R trajectory beyond the original observation period

Running the synthetic validation locally now to provide evidence.

@sbfnk-bot
Copy link
Collaborator Author

Synthetic validation evidence:

Ran the core rt.R scenario locally with the fix:

Initial fit complete
forecast_infections with extended R: SUCCESS
get_samples: SUCCESS
Extracted sim_cases, nrow: 140 

Synthetic validation core steps completed successfully!

This confirms the fix works for the exact scenario that was failing (140-element R trajectory on a 100-day fit).

@sbfnk-bot
Copy link
Collaborator Author

Triggered the synthetic validation workflow on this branch: https://github.com/epiforecasts/EpiNow2/actions/runs/22853331016

This should pass now (previous runs were failing with the date-dimension mismatch bug this PR fixes).

@sbfnk sbfnk requested a review from seabbs March 9, 2026 12:53
@sbfnk sbfnk added this pull request to the merge queue Mar 9, 2026
Merged via the queue into main with commit 396f33f Mar 9, 2026
13 checks passed
@sbfnk sbfnk deleted the fix-forecast-infections-dates branch March 9, 2026 14:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Synthetic validation check failing since January 2025

3 participants