Skip to content

BOT: Fix #983: Create .data.frame methods for as_forecast_* generics#1077

Closed
nikosbosse wants to merge 3 commits intomainfrom
fix/983-as-forecast-data-frame-methods
Closed

BOT: Fix #983: Create .data.frame methods for as_forecast_* generics#1077
nikosbosse wants to merge 3 commits intomainfrom
fix/983-as-forecast-data-frame-methods

Conversation

@nikosbosse
Copy link
Copy Markdown
Collaborator

@nikosbosse nikosbosse commented Feb 13, 2026

CLAUDE:

Summary

  • Renames the 8 existing .default methods for as_forecast_*() generics to .data.frame methods, since they assume data.frame-like input
  • Creates new .default methods that error with a clear message when non-data.frame input is provided (e.g. vectors, matrices, lists)
  • Adds tibble to Suggests for test coverage of tibble dispatch

Fixes #983

Root cause

All as_forecast_*() generics only had .default methods which silently accepted any type via as.data.table() coercion in ensure_data.table(). This meant vectors, matrices, and other non-data.frame types would either silently produce nonsensical results or fail with confusing deep validation errors.

What the fix does

  • Renamed .default.data.frame for all 8 forecast types (binary, point, sample, quantile, nominal, ordinal, multivariate_sample, multivariate_point)
  • Created new .default methods that immediately error with: "Input must be a data.frame or similar (e.g. a data.table or tibble), not <class>."
  • S3 dispatch ensures data.table and tibble inputs still route to the .data.frame method since both inherit from data.frame

Test coverage added

  • Tests covering:
    • Plain data.frame input works for all types (regression guards)
    • data.table input still dispatches correctly via S3
    • Non-data.frame input (vectors, matrices, lists, strings) produces clear errors for all types
    • Column renaming functionality preserved after method rename
    • tibble input dispatches correctly

Test plan

  • All 789 tests pass (0 failures, 0 warnings)
  • Linter passes
  • Codecov patch and project checks pass

🤖 Generated with Claude Code

Rename the 7 existing .default methods to .data.frame (since they
assume data.frame-like input), then create new .default methods that
error with a helpful message about unsupported types. This ensures
non-data.frame inputs (vectors, matrices, lists) get a clear error
instead of being silently coerced via as.data.table().

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
nikosbosse added a commit that referenced this pull request Feb 13, 2026
@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 (4a222da) to head (515abd3).
⚠️ Report is 26 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1077      +/-   ##
==========================================
+ Coverage   97.98%   98.00%   +0.02%     
==========================================
  Files          37       37              
  Lines        1984     2008      +24     
==========================================
+ Hits         1944     1968      +24     
  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.

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: Clean, well-structured PR. Correctly renames .default to .data.frame across all 7 as_forecast_*() generics and adds new .default methods that error with clear messages for non-data.frame input. S3 dispatch is correctly leveraged for data.table and tibble inheritance. NAMESPACE, documentation, and tests are all consistent. 12 new tests cover regression guards, dispatch correctness, error handling, column renaming, and tibble compatibility. Two very minor cosmetic notes: (1) as_forecast_sample.data.frame is missing the explicit @method roxygen tag (inferred correctly, no functional impact), (2) the data.table dispatch test covers 6/7 types (missing multivariate_sample, very low risk). Verdict: approve.

@nikosbosse nikosbosse marked this pull request as draft February 13, 2026 08:27
@nikosbosse nikosbosse changed the title Fix #983: Create .data.frame methods for as_forecast_* generics BOT: Fix #983: Create .data.frame methods for as_forecast_* generics Feb 13, 2026
nikosbosse and others added 2 commits April 4, 2026 21:01
Resolves merge conflicts in NAMESPACE and
R/class-forecast-multivariate-sample.R, keeping the .data.frame
method rename from this branch combined with main's updated
signature (joint_across = NULL).

Also fixes:
- @inheritParams references updated from .default to .data.frame
  in multivariate-sample and multivariate-point
- Test class name updated (forecast_sample_multivariate ->
  forecast_multivariate_sample) to match main's rename
- Added missing test coverage for .default error methods on
  point, nominal, ordinal, and multivariate_sample types
  (addresses codecov/patch failure)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- Rename as_forecast_multivariate_point.default to .data.frame
  (the implementation method) matching the PR's pattern
- Add new .default error method for non-data.frame input
- Add test coverage for the new .default error method
- Fix indentation lint in test-class-forecast-multivariate-sample.R

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

@seabbs it's not a great PR, but it's not a bad PR either. I have no strong attachments to it, but I think it's fine to merge

@seabbs
Copy link
Copy Markdown
Contributor

seabbs commented Apr 20, 2026

Isn't this a breaking change?

Copy link
Copy Markdown
Contributor

@seabbs seabbs left a comment

Choose a reason for hiding this comment

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

I think as written this is a breaking change as the default input goes from anything that be coerced into a data.table into anything that is a data.frame. That should at the minimum require changes to the documentation (which should say above). Do we have user reports saying this is an issue etc etc. I think not and based on that I wonder if we should just leave as is, perhaps check to make sure the docs are clear, and close the target issue?

@nikosbosse
Copy link
Copy Markdown
Collaborator Author

Huh. It didn't occur to me that there might be things you could coerce into a data.table that aren't a data.frame. But yeah, lists are famously that...
Good catch, thank you. Just didn't think of it. The PR is more meant to clean things up, I don't think there is any actual user need. Let shelve it.

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.

Create .data.frame methods for as_forecast<type>

2 participants