Repository navigation
Validate forecasts only twice in transform_forecasts() (#1236) - #1238
Open
nikosbosse wants to merge 3 commits into
Open
nikosbosse wants to merge 3 commits into
nikosbosse wants to merge 3 commits into
Conversation
transform_forecasts() updated the forecast object with :=, and `[.forecast` re-validates after every such update, so the full validation ran six times per call. The transformation now runs on a plain data.table in an internal helper, and each method rebuilds the forecast object once at the end. Closes #1236. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #1238 +/- ##
==========================================
- Coverage 99.18% 99.18% -0.01%
==========================================
Files 41 41
Lines 2333 2331 -2
==========================================
- Hits 2314 2312 -2
Misses 19 19 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
- Error clearly when append = FALSE reuses a label already in 'scale' - Keep .mv_group_id for multivariate forecasts with append = FALSE instead of re-inferring joint_across, which fails when every forecast unit column is constant within groups - Drop a redundant copy of the data - Broaden tests to multivariate forecasts and existing 'scale' columns Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
nikosbosse
commented
Oct 26, 2026
nikosbosse
left a comment
Collaborator
Author
There was a problem hiding this comment.
@seabbs looks good to me
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
CLAUDE: Closes #1236.
What
transform_forecasts()updated the forecast object with:=, and[.forecastre-validates the whole object after every such update. One call therefore ranassert_forecast()six times withappend = TRUEand three times withappend = FALSE. Multivariate forecasts paid for one more validation on top, because the method rebuilt an object that had just been built.The transformation now lives in an internal helper,
transform_forecast_data(). It validates the input once (clean_forecast()) and does all:=updates and therbind()on a plaindata.table. Each method then builds the forecast object once with the matchingas_forecast_<type>(). That makes two validations per call for every forecast type and both values ofappend. Withappend = FALSE, multivariate forecasts keep their existing.mv_group_id, since the rows and groups don't change.The smaller items in the issue (
check_observed_constant(),check_number_per_forecast(),get_duplicate_forecasts()) are left for a separate PR.Timing
On the reprex in #1236 (120k quantile forecasts, 2.76M rows):
append = TRUEappend = FALSEThe remaining time is mostly the two validations; the output of
append = TRUEhas twice as many rows as the input. Skipping input validation would save about another 2 s, but then invalid input would fail insidefun()with an obscure error.Behaviour change
With
append = FALSE, a transformation that produced an invalid forecast used to return it, with "Error in validating forecast object" warnings. It now errors, as it already did withappend = TRUE. For example,fun = as.characternow errors, and so does afunthat returns allNA. This is in NEWS.The most likely way to hit this is calling
append = FALSEon an already-transformed forecast with alabelthat is already inscale. That includes the default"log"after a default transformation. That call duplicates forecasts, so it now gets its own clear error ("Can't transform with label 'log' ...") instead of a duplicate-forecast error. Thelabeldocs now say this.Checks
append = TRUE,append = FALSE, andappend = FALSEon an already-transformed object with a new label.scalecolumn;append = FALSE.devtools::test()passes.lintrreports no lints on the changed files. Coverage ofR/transform-forecasts.Rstays at 100%.🤖 Generated with Claude Code