BOT: Fix #983: Create .data.frame methods for as_forecast_* generics#1077
BOT: Fix #983: Create .data.frame methods for as_forecast_* generics#1077nikosbosse wants to merge 3 commits intomainfrom
Conversation
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>
Codecov Report✅ All modified and coverable lines are covered by tests. 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. 🚀 New features to boost your workflow:
|
nikosbosse
left a comment
There was a problem hiding this comment.
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.
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>
|
@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 |
|
Isn't this a breaking change? |
seabbs
left a comment
There was a problem hiding this comment.
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?
|
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... |
CLAUDE:
Summary
.defaultmethods foras_forecast_*()generics to.data.framemethods, since they assume data.frame-like input.defaultmethods that error with a clear message when non-data.frame input is provided (e.g. vectors, matrices, lists)tibbletoSuggestsfor test coverage of tibble dispatchFixes #983
Root cause
All
as_forecast_*()generics only had.defaultmethods which silently accepted any type viaas.data.table()coercion inensure_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
.default→.data.framefor all 8 forecast types (binary, point, sample, quantile, nominal, ordinal, multivariate_sample, multivariate_point).defaultmethods that immediately error with:"Input must be a data.frame or similar (e.g. a data.table or tibble), not <class>."data.tableandtibbleinputs still route to the.data.framemethod since both inherit fromdata.frameTest coverage added
data.frameinput works for all types (regression guards)data.tableinput still dispatches correctly via S3tibbleinput dispatches correctlyTest plan
🤖 Generated with Claude Code