1196: Fix as_forecast_quantile() from samples for asymmetric probs - #1218
1196: Fix as_forecast_quantile() from samples for asymmetric probs#1218nikosbosse wants to merge 3 commits into
Conversation
as_forecast_quantile.forecast_sample() built the quantile_level column from a symmetrised vector unique(round(c(probs, 1 - probs), 10)) while computing the quantiles at the raw probs, a refactoring regression from 4d9ecf7 (#876). For asymmetric probs this silently paired quantile values with the wrong levels (via length-1 recycling) or errored; for duplicated probs it triggered a duplicate-forecast assertion. Quantiles are now computed at exactly the requested (deduplicated) probs, matching the documentation. Symmetric prob sets, including the default, produce byte-identical output to before. probs is now also bounded to [0, 1] for a clearer early error. 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 #1218 +/- ##
==========================================
- Coverage 98.15% 98.15% -0.01%
==========================================
Files 41 41
Lines 2225 2224 -1
==========================================
- Hits 2184 2183 -1
Misses 41 41 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
Automated review (Claude Fable, directed by @nikosbosse): Verdict: approve. Checks performed (in an isolated detached worktree at e56c754):
One minor observation (not blocking, pre-existing on main): |
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Follow-up to the review of the asymmetric-probs fix (#1196): probs containing NA (e.g. c(0.5, NA)) previously passed the assert_numeric() bounds check (checkmate bounds ignore NAs) and silently produced rows with quantile_level = NA / predicted = NA. Add any.missing = FALSE so this now fails with a clear assertion error, plus a regression test. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
|
Follow-up (Claude Fable, directed by @nikosbosse): addressed the review observation about missing values in
Verification: |
|
lgtm |
Description
This PR closes #1196.
as_forecast_quantile.forecast_sample()built thequantile_levelcolumn from a symmetrised vectorunique(round(c(probs, 1 - probs), 10))while computing the actual quantiles at the rawprobs— a refactoring regression from 4d9ecf7 (#876), where the predecessorsample_to_quantile()used the same symmetrised vector for both. As a result, anyprobsnot symmetric around 0.5 either silently paired quantile values with the wrong levels (via data.table length-1 recycling) or errored, and duplicated probs triggered a duplicate-forecast assertion.The fix (per maintainer decision, Option B): compute quantiles at exactly the requested probs, using a single
quantile_level <- unique(round(probs, digits = 10))for both the column and thequantile()call — matching the documented behaviour ofprobs. For every symmetric prob set, including the defaultc(0.05, 0.25, 0.5, 0.75, 0.95), the output is byte-identical to before. The input check is also tightened toassert_numeric(probs, min.len = 1, lower = 0, upper = 1)for a clearer early error on out-of-range probs.New tests failed as expected before the fix:
All tests pass after the fix; the full suite passes on main + this change (0 failed, 916 passed).
Dev note: bug identified by an LLM audit (#1189); fix and tests implemented with LLM support, directed by @nikosbosse.
Checklist
probs).