1199: Error when as_forecast_<type>() renaming would create duplicate columns#1212
Open
nikosbosse wants to merge 1 commit into
Open
1199: Error when as_forecast_<type>() renaming would create duplicate columns#1212nikosbosse wants to merge 1 commit into
nikosbosse wants to merge 1 commit into
Conversation
…1199) as_forecast_generic() called setnames() without checking whether a rename target already existed as a column in the data. Renaming e.g. predicted = "prob" while a stale `predicted` column was present created a forecast object with two `predicted` columns that passed validation and was scored on the wrong column. - as_forecast_generic() now errors with a clear message when a rename would collide with an existing column that is not itself being renamed away. Identity renames and simultaneous swaps still work. - assert_forecast_generic() now rejects data with duplicate column names, so corrupt objects from any other construction route fail validation instead of passing silently. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #1212 +/- ##
==========================================
+ Coverage 98.15% 98.17% +0.01%
==========================================
Files 41 41
Lines 2225 2241 +16
==========================================
+ Hits 2184 2200 +16
Misses 41 41 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Collaborator
Author
|
Automated review (Claude Fable, directed by @nikosbosse): Verdict: approve. Verified independently in an isolated checkout of the branch (7a93d80):
Minor (non-blocking): the collision error names only the target column (e.g. No must-fix findings. |
nikosbosse
marked this pull request as draft
July 18, 2026 13:53
nikosbosse
marked this pull request as ready for review
July 18, 2026 20:41
Collaborator
Author
|
We're now enforcing unique column names, which is a slight behaviour change, but I think it's a good one |
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.
Description
This PR closes #1199.
as_forecast_generic()calleddata.table::setnames()without checking whether a rename target already existed as a column in the data. Calling e.g.as_forecast_binary(dt, predicted = "prob")while a stalepredictedcolumn was present silently created a forecast object with twopredictedcolumns. That object passedassert_forecast()and was then scored on the wrong (stale) column, producing silently wrong scores. All eightas_forecast_<type>()constructors route through this function.The fix (per the settled maintainer decision — error, no silent overwrite, no deprecation period):
as_forecast_generic()now errors with a clearcli_abort()message when a rename would collide with an existing column that is not itself being renamed away. Identity renames (observed = "observed") and simultaneous swaps of renameable columns still work.assert_forecast_generic()now rejects data with duplicate column names, so corrupt objects reached by any other construction route fail validation instead of passing silently.Tests were written first and failed against the unfixed code:
With the fix, the affected test files and the full test suite pass (0 failed, 910 passed, 0 skipped).
Dev note: bug identified by an LLM audit (#1189); fix and tests implemented with LLM support, directed by @nikosbosse.
Checklist
@importFromroxygen tag was added;devtools::document()produced no changes toman/orNAMESPACE).lintron the changed files; no new lints were introduced.