Repository navigation
880: Allow choosing the quantile in as_forecast_point.forecast_quantile() - #1243
Draft
nikosbosse wants to merge 4 commits into
Draft
nikosbosse wants to merge 4 commits into
nikosbosse wants to merge 4 commits into
Conversation
#880) Add a quantile_level argument (default 0.5) that selects which quantile is extracted as the point forecast. The value is validated to be a single number in [0, 1] that is present in the data. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Match the specific checkmate message for each invalid input so each expectation shows which assertion fired, add a row-count check, and state the length-one requirement in the @PARAM text. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…oint() Compare quantile levels on values rounded to 10 digits so that levels built with seq() (e.g. 0.15, 0.7) can be extracted, raise a cli error listing the available levels when the requested one is missing, note that the argument is ignored for non-quantile inputs, and drop the duplicate assert_subset import. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #1243 +/- ##
=======================================
Coverage 99.18% 99.18%
=======================================
Files 41 41
Lines 2333 2340 +7
=======================================
+ Hits 2314 2321 +7
Misses 19 19 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
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:
Description
This PR closes #880.
as_forecast_point.forecast_quantile()used to hard-code the 0.5 quantile as the point forecast. This PR adds aquantile_levelargument (default0.5, so existing behaviour is unchanged) that selects which quantile is extracted, e.g.as_forecast_point(data, quantile_level = 0.75).quantile_levelis checked withassert_number(lower = 0, upper = 1). If the requested level is not present in the data, acli_abort()error names the level and lists the available ones.round(..., 10)idiom used inget_coverage()/ the quantile metrics). Levels built with e.g.seq(0.05, 0.95, 0.05)(stored as0.15000000000000002) can therefore be extracted withquantile_level = 0.15.quantile_levelmatches the column name used throughout the package. Because the column and the argument share a name, the function stores the (rounded) argument in a localtarget_levelbefore subsetting with data.table. If maintainers prefer a different argument name, that is an easy change.forecast_quantileobjects (the default method swallows it via...).Implementation: two independent drafts were compared by a judge agent; draft A was chosen as base (with tighter error-message expectations grafted from draft B).
Review
An independent adversarial agent review was done. Changes made in response:
round(..., 10)on both sides; added a test with levels fromseq(0.05, 0.95, 0.05)extracting0.15and0.7, verified to fail on the previous branch state and pass now.assert_subset()with acli_abort()listing the available levels; test expectation updated (also verified to fail before).assert_subsetimport: applied; tag reduced to@importFrom checkmate assert_number(pluscli_abort)."quantile_level".quantile_levelsilently swallowed byas_forecast_point.default(): partly applied, the code change is rebutted. The param doc now says the argument is ignored for other inputs. No runtime check was added: passing a plain long-format quantile data.frame to the default method already errors loudly (duplicate forecasts per forecast unit), so the realistic mistake is not silent, andrlang::check_dots_empty()would break existing callers that pass extra arguments through.... Out of scope for this PR.quantile_levelname in Allow users to specify the quantile in `as_forecast_point.forecast_quantile()? #880 before marking it ready.Checklist
devtools::test()passes (0 failures).test_thatblocks intest-class-forecast-point.R(extraction of default/0.75 quantile; extraction of non-exactly-representable levels fromseq(); validation ofquantile_level). Verified they fail before the respective changes and pass after.man/as_forecast_point.Rdchanges.)lintr::lint_package()to check for style issues introduced by my changes. Ranlintr::lint()on the changed files: no lints in the test file; the only lints in the R file are the pre-existing spurious "no visible binding/global function" warnings that appear when the package is not installed.🤖 Generated with Claude Code