Skip to content

880: Allow choosing the quantile in as_forecast_point.forecast_quantile() - #1243

Draft
nikosbosse wants to merge 4 commits into
mainfrom
issue-880-quantile-level-as-forecast-point
Draft

nikosbosse wants to merge 4 commits into
mainfrom
issue-880-quantile-level-as-forecast-point

Conversation

@nikosbosse

@nikosbosse nikosbosse commented Nov 8, 2026 •

Copy link
Copy Markdown
Collaborator

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 a quantile_level argument (default 0.5, so existing behaviour is unchanged) that selects which quantile is extracted, e.g. as_forecast_point(data, quantile_level = 0.75).

  • quantile_level is checked with assert_number(lower = 0, upper = 1). If the requested level is not present in the data, a cli_abort() error names the level and lists the available ones.
  • Floating-point robust matching: the requested level and the levels in the data are both rounded to 10 digits before comparing (the same round(..., 10) idiom used in get_coverage() / the quantile metrics). Levels built with e.g. seq(0.05, 0.95, 0.05) (stored as 0.15000000000000002) can therefore be extracted with quantile_level = 0.15.
  • Argument name: quantile_level matches the column name used throughout the package. Because the column and the argument share a name, the function stores the (rounded) argument in a local target_level before subsetting with data.table. If maintainers prefer a different argument name, that is an easy change.
  • The argument is documented as ignored for inputs that are not forecast_quantile objects (the default method swallows it via ...).
  • Roxygen docs / Rd updated; NEWS bullet added.

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:

  • Floating-point matching (major): applied. Comparison now uses round(..., 10) on both sides; added a test with levels from seq(0.05, 0.95, 0.05) extracting 0.15 and 0.7, verified to fail on the previous branch state and pass now.
  • Raw checkmate error for missing levels: applied. Replaced assert_subset() with a cli_abort() listing the available levels; test expectation updated (also verified to fail before).
  • Duplicate assert_subset import: applied; tag reduced to @importFrom checkmate assert_number (plus cli_abort).
  • Brittle checkmate-message expectations: applied; those tests now match on "quantile_level".
  • quantile_level silently swallowed by as_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, and rlang::check_dots_empty() would break existing callers that pass extra arguments through .... Out of scope for this PR.
  • Maintainer confirmation of the feature / argument name: noted. The PR stays a draft; maintainers should confirm the quantile_level name in Allow users to specify the quantile in `as_forecast_point.forecast_quantile()? #880 before marking it ready.

Checklist

  • My PR is based on a package issue and I have explicitly linked it.
  • I have included the target issue or issues in the PR title as follows: issue-number: PR title
  • I have tested my changes locally. Full devtools::test() passes (0 failures).
  • I have added or updated unit tests where necessary. Three new test_that blocks in test-class-forecast-point.R (extraction of default/0.75 quantile; extraction of non-exactly-representable levels from seq(); validation of quantile_level). Verified they fail before the respective changes and pass after.
  • I have updated the documentation if required.
  • I have built the package locally and run rebuilt docs using roxygen2. (Local roxygen2 is 8.0.0 vs the repo's 7.3.3; unrelated NAMESPACE reformatting churn was reverted, only man/as_forecast_point.Rd changes.)
  • My code follows the established coding standards and I have run lintr::lint_package() to check for style issues introduced by my changes. Ran lintr::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.
  • I have added a news item linked to this PR.
  • I have reviewed CI checks for this PR and addressed them as far as I am able. No CI checks have been reported on this branch yet.

🤖 Generated with Claude Code

nikosbosse and others added 4 commits November 8, 2026 13:07
#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

codecov Bot commented Nov 8, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.18%. Comparing base (8b18f07) to head (e1661f3).

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Allow users to specify the quantile in `as_forecast_point.forecast_quantile()?

1 participant