1201: Error on conflicting observed values within a forecast unit#1207
Open
nikosbosse wants to merge 2 commits into
Open
1201: Error on conflicting observed values within a forecast unit#1207nikosbosse wants to merge 2 commits into
nikosbosse wants to merge 2 commits into
Conversation
…st unit (#1201) Add an internal check, check_observed_constant(), called from assert_forecast_generic(), that errors when rows belonging to the same forecast unit have different observed values. Previously such invalid data passed validation for quantile, sample, nominal, ordinal and multivariate sample forecasts and score() silently returned multiple wrong score rows for a single forecast. Rows with NA observed values are ignored by the check. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #1207 +/- ##
==========================================
+ Coverage 98.15% 98.16% +0.01%
==========================================
Files 41 41
Lines 2225 2239 +14
==========================================
+ Hits 2184 2198 +14
Misses 41 41 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Collaborator
Author
|
Automated review (Claude Fable, directed by @nikosbosse): Verdict: approve. Verified in an isolated worktree at the PR head commit.
Minor, non-blocking:
|
nikosbosse
marked this pull request as draft
July 18, 2026 13:53
nikosbosse
marked this pull request as ready for review
July 18, 2026 21:04
Collaborator
Author
|
lgtm |
- Add an automated test that as_forecast_ordinal() errors on conflicting observed values within a forecast unit - Remove extra blank line after check_observed_constant() Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Collaborator
Author
|
Follow-up (Claude Fable, directed by @nikosbosse): addressed both minor review findings in a11159e.
Verification: |
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.
Description
This PR closes #1201.
Forecast validation accepted data in which the
observedvalue differed across rows of the same forecast unit. Such data passedas_forecast_quantile(),as_forecast_sample(),as_forecast_nominal(),as_forecast_ordinal()andas_forecast_multivariate_sample()without complaint, andscore()then silently produced multiple wrong score rows for a single forecast (e.g. a quantile forecast withobserved = c(10, 10, 20)across three quantile levels validated fine and yielded twowisrows: 7.67 and 17.67). The existing duplicate check groups byc(forecast_unit, type_cols), so rows differing only inobservedwere never flagged, and theobserved = unique(observed)aggregation in thescore()methods silently recycled.The fix adds an internal check,
check_observed_constant(), called fromassert_forecast_generic()right after the duplicate check, which errors (per maintainer decision: hard error, wording mirroring the duplicate-forecasts message) when a forecast unit has more than one distinct non-NAobserved value. Because it lives in the generic validation,as_forecast_*(),assert_forecast(),score()and[.forecastall catch it, for every forecast type. Rows withNAobserved are ignored, and multivariate forecasts need no special-casing: the forecast unit is the univariate unit, within which observed is legitimately constant (a regression test usingexample_sample_continuouswithjoint_across = c("location", "location_name")guards this).Tests were written first and failed against the unfixed code:
After the fix, the full test suite passes (0 failed, 915 passed).
Note: this is a user-facing behaviour change — previously accepted (but silently mis-scored) data now errors at validation. A NEWS.md entry documents this.
Dev note: bug identified by an LLM audit (#1189); fix and tests implemented with LLM support, directed by @nikosbosse.
Checklist
lintr::lint()on the changed files to check for style issues introduced by my changes.