Skip to content

Fix #1043: Add print method for multivariate forecasts showing joint_across#1074

Open
nikosbosse wants to merge 8 commits intomainfrom
fix/1043-multivariate-print-joint-across
Open

Fix #1043: Add print method for multivariate forecasts showing joint_across#1074
nikosbosse wants to merge 8 commits intomainfrom
fix/1043-multivariate-print-joint-across

Conversation

@nikosbosse
Copy link
Copy Markdown
Collaborator

@nikosbosse nikosbosse commented Feb 13, 2026

CLAUDE:

Summary

  • Adds print.forecast_multivariate_sample() and print.forecast_multivariate_point() S3 methods that display which columns are jointly forecasted
  • Both methods delegate to a shared print_multivariate_forecast() helper that computes joint_across as setdiff(get_forecast_unit(x), get_grouping(x)) and shows it between forecast unit and data table output
  • Fixes the original method name from print.forecast_sample_multivariate (old class name) to print.forecast_multivariate_sample (current class name)

Root cause

No dedicated print methods existed for multivariate forecast objects — they fell through to the generic print.forecast(), which only shows forecast type and forecast unit but has no awareness of joint_across or the .mv_group_id grouping structure. Additionally, the original PR had the method named after the old class (forecast_sample_multivariate) so it was never dispatched.

What the fix does

Creates print_multivariate_forecast() in R/class-forecast-multivariate-sample.R that:

  1. Prints forecast type and forecast unit (matching print.forecast() behavior)
  2. Computes joint_across columns from the difference between forecast unit and grouping columns
  3. Displays "Joint across:" followed by the column names
  4. Prints the data table via print(as.data.table(x))
  5. Returns the input invisibly

Both print.forecast_multivariate_sample() and print.forecast_multivariate_point() are thin wrappers that delegate to this helper.

Test plan

  • Snapshot tests for both sample and point print output
  • Returns object invisibly (both types)
  • Output contains all expected sections (type, unit, joint_across)
  • Error branches covered (mocked get_forecast_type and get_forecast_unit)
  • Full test suite passes (766 tests, 0 failures)

Closes #1043

🤖 Generated with Claude Code

…t_across

Add print.forecast_sample_multivariate() S3 method that displays which
columns are jointly forecasted. The method computes joint_across as
setdiff(get_forecast_unit(), get_grouping()) and shows it alongside
the forecast type and forecast unit.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@codecov
Copy link
Copy Markdown

codecov bot commented Feb 13, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.00%. Comparing base (d4bbd6e) to head (6430464).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1074      +/-   ##
==========================================
+ Coverage   97.98%   98.00%   +0.01%     
==========================================
  Files          37       37              
  Lines        1984     2001      +17     
==========================================
+ Hits         1944     1961      +17     
  Misses         40       40              

☔ View full report in Codecov by Sentry.
📢 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.

nikosbosse added a commit that referenced this pull request Feb 13, 2026
Copy link
Copy Markdown
Collaborator Author

@nikosbosse nikosbosse left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CLAUDE: Approve (posted as comment due to GitHub self-review restriction). Clean, focused implementation of print.forecast_sample_multivariate() that correctly computes joint_across via setdiff(get_forecast_unit(x), get_grouping(x)) and displays it in the print output. All 5 tests pass and match specs. Three minor notes: (1) the method duplicates ~30 lines from print.forecast() rather than using NextMethod() — deliberate to insert the "Joint across:" line, but creates maintenance coupling; (2) @importFrom cli cli_inform is missing from the roxygen tag (works via package-level NAMESPACE but not best practice); (3) Test 5 name says "still calls parent print.forecast()" but the implementation replicates the parent's logic instead of calling it — the test itself is valid, just the name is misleading.

@nikosbosse nikosbosse marked this pull request as draft February 13, 2026 08:26
@nikosbosse nikosbosse changed the title Fix #1043: Add print method for multivariate forecasts showing joint_across BOT: Fix #1043: Add print method for multivariate forecasts showing joint_across Feb 13, 2026
- Add fixed = TRUE to grepl calls (fixed_regex_linter)
- Add tests for forecast_type and forecast_unit error branches
  to improve code coverage

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@nikosbosse
Copy link
Copy Markdown
Collaborator Author

CLAUDE: Here's an example of the new print output for example_multivariate_sample:

> print(example_multivariate_sample)
Forecast type: multivariate_sample
Forecast unit:
location, location_name, target_end_date, target_type, forecast_date, model,
and horizon
Joint across:
location and location_name

       location location_name target_end_date target_type forecast_date
         <char>        <char>          <Date>      <char>        <Date>
    1:       DE       Germany      2021-01-02       Cases          <NA>
    2:       DE       Germany      2021-01-02      Deaths          <NA>
    3:       DE       Germany      2021-01-09       Cases          <NA>
    ...
35624: epiforecasts-EpiNow2       2  24.43419        40       78          260

The new "Joint across" line shows which columns vary within each multivariate group (i.e., location and location_name are the dimensions being jointly forecasted), which is the key information that was previously invisible when falling through to the generic print.forecast().

Also pushed a fix for the lint errors (fixed = TRUE in grepl calls) and added tests for the error branches to address the codecov gap.

nikosbosse and others added 2 commits April 4, 2026 22:19
- Rename print.forecast_sample_multivariate to
  print.forecast_multivariate_sample to match actual class name
- Add print.forecast_multivariate_point with same behavior
- Extract shared print_multivariate_forecast() helper
- Add tests for multivariate point print method
- Fix broken forecast_type test to use mock instead of class manipulation

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@nikosbosse nikosbosse changed the title BOT: Fix #1043: Add print method for multivariate forecasts showing joint_across Fix #1043: Add print method for multivariate forecasts showing joint_across Apr 4, 2026
nikosbosse and others added 4 commits April 4, 2026 22:47
Prevent local Claude Code configuration files from being
accidentally committed to the repository.

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
The joint_across display logic in print.forecast() is now unreachable
since multivariate forecasts dispatch to their own dedicated print
methods (print.forecast_multivariate_sample and
print.forecast_multivariate_point). Removing it eliminates uncovered
lines and improves project coverage.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@nikosbosse nikosbosse marked this pull request as ready for review April 5, 2026 11:18
@nikosbosse nikosbosse requested a review from seabbs April 5, 2026 11:20
@nikosbosse
Copy link
Copy Markdown
Collaborator Author

@seabbs I think adding joint across to the print output would be nice. Things we could consider in the future

  • the multivariat forecast class
  • extracting the joint across code into a helper

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.

Update print method for multivariate forecasts to show joint_across

1 participant