1196: Fix as_forecast_quantile() from samples for asymmetric probs#1218
Draft
nikosbosse wants to merge 2 commits into
Draft
1196: Fix as_forecast_quantile() from samples for asymmetric probs#1218nikosbosse wants to merge 2 commits into
nikosbosse wants to merge 2 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:
|
Collaborator
Author
|
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>
nikosbosse
marked this pull request as draft
July 18, 2026 13:53
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 #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).