Skip to content

fix: display latency adjustment info on canned forecasters (#447)#477

Open
gregfaletto wants to merge 1 commit intocmu-delphi:devfrom
gregfaletto:fix-print-canned-pre-447
Open

fix: display latency adjustment info on canned forecasters (#447)#477
gregfaletto wants to merge 1 commit intocmu-delphi:devfrom
gregfaletto:fix-print-canned-pre-447

Conversation

@gregfaletto
Copy link
Copy Markdown

Resolves #447.

Summary

print.canned_epipred() was supposed to surface latency-adjustment information (e.g., Aheads adjusted per column: case_rate=2, death_rate=3) for canned forecasters whose recipe contains a step_adjust_latency. It never actually did, because the gating conditional checked for a top-level pre field on the canned forecaster object — but canned forecasters' top-level fields are predictions, epi_workflow, and metadata. The conditional was always FALSE, and the entire latency-info block was dead code.

The fix replaces the conditional with !is.null(x$epi_workflow$pre$actions$recipe), which correctly tests for a recipe preprocessor on the embedded workflow. The latency-info display now works for all four recipe-based canned forecasters (arx_forecaster, arx_classifier, cdc_baseline_forecaster, flatline_forecaster); climatological_forecaster correctly remains unaffected (it overwrites pre with a mold-only list and has no step_adjust_latency).

Test coverage

The existing snapshot tests in tests/testthat/test-snapshots.R already exercised arx_forecaster with adjust_latency = "extend_lags" (out2) and "extend_ahead" (out3) but never observed the latency line because of the bug. Their snapshots regenerate to include the new lines (one + line each in _snaps/snapshots.md — purely additive). Two supplementary expect_match("adjusted", ...) assertions are added next to those snapshot calls as defensive guards: if a future contributor mechanically snapshot_accepts after an unrelated upstream change drops the "adjusted" line, the explicit assertions still catch the regression.

Bookkeeping

  • NEWS.md: new # epipredict 0.2.3 section with one bullet.
  • DESCRIPTION: version bumped to 0.2.3.
  • .gitignore and .Rbuildignore: 3 lines each adding .workflow/, .plans/, and .claude/ to keep personal tooling directories out of git tracking and out of the package build tarball. Happy to split into a separate PR if you prefer.

Out of scope

The original issue mentions a broader concern about partial-matching vulnerabilities in epi_archive / epi_df list subclasses. Those types live in epiprocess, not epipredict. Within this repo, I confirmed via grep that R/canned-epipred.R:115 was the only x$pre access where x was not a workflow object; the others (R/epi_recipe.R:308, R/extract.R:88, R/model-methods.R:89) all operate on workflow objects where pre is the actual field name. A broader audit belongs as a follow-up epiprocess issue.

Test plan

  • devtools::test() — 910 passing, 0 failing, 2 skips. The skips (test-get_test_data.R:47 "NA fill behaves as desired" and :85 "forecast date behaves") are pre-existing on dev, added in commit 09fbfd812 (July 2024) as placeholders during the locf-into-step_adjust_ahead refactor; the underlying get_test_data rework is tracked by PR Get test data rework #463 and issues Bug: get_test_data uses na.omit() on all data table columns, rather than just predictors/outcomes #468 / get_test_data returning NA's if there are NA's in the most recent data #267.
  • devtools::check(document = FALSE, vignettes = FALSE) — 0 errors. 1 environmental warning (parsnip binary built under R 4.5.2 vs local R 4.5.0 — won't fire in CI). 2 pre-existing notes on dev (top-level Makefile/pkgdown-watch.R, deep ::: import list).
  • lintr::lint_package() — zero new findings on lines added by this PR.
  • Manually verified before/after: arx_forecaster with step_adjust_latency now shows the latency-adjustment bullet at the bottom of print() output.

…i#447)

print.canned_epipred() was supposed to surface latency-adjustment
information for canned forecasters whose recipe contains a
step_adjust_latency. The gating conditional checked for a top-level
"pre" field on the canned forecaster, but canned forecasters'
top-level fields are predictions, epi_workflow, and metadata. The
check always evaluated FALSE, leaving the latency-info block as dead
code.

Replace the predicate with !is.null(x$epi_workflow$pre$actions$recipe),
which correctly tests for a recipe preprocessor on the embedded
workflow.

The existing snapshot tests for arx_forecaster with extend_lags and
extend_ahead regenerate to include the previously-missing
"Lags adjusted" / "Aheads adjusted" lines. Two supplementary
expect_match assertions are added as defensive guards.

Also adds .workflow/, .plans/, .claude/ to both .gitignore and
.Rbuildignore for personal agent-tooling directories.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@gregfaletto gregfaletto requested a review from dajmcdon as a code owner May 6, 2026 02:20
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.

print.canned_pred checks contents of non-existent pre (partial-matched to unintended element)

1 participant