[Repo Assist] fix(gcm/unit_change): raise ValueError when input column named 'f' conflicts with mechanism output - #1785
Draft
github-actions[bot] wants to merge 1 commit into
Conversation
…nflicts with mechanism output The unit_change_linear and unit_change_nonlinear functions add a column named 'f' to the output DataFrame for the mechanism contribution. If a caller passes an input_column_names list that already contains 'f', the mechanism value silently overwrites the input attribution, producing incorrect results with no error. Add a _check_no_reserved_column_name() guard (called alongside the existing _check_if_input_columns_exist check) that raises ValueError with a clear message when 'f' appears in input_column_names. Also add a test that covers both unit_change_linear and unit_change_nonlinear. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
This was referenced Aug 31, 2026
This branch has not been deployed
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.
🤖 This PR was created by Repo Assist, an automated AI assistant.
Problem
unit_change_linearandunit_change_nonlinearappend a column named"f"to the output DataFrame to hold the mechanism's contribution. If the caller passesinput_column_namesthat already contains"f", the newly appended"f"column silently overwrites the input attribution for the"f"variable, producing incorrect results with no warning or error.The code even had a
# TODO: Handle the case where 'f' is an input column namecomment acknowledging this issue.Root Cause
If
"f"is ininput_column_names,contribution_df["f"]already exists and gets overwritten bycontribution_mechanism.Fix
Added
_check_no_reserved_column_name()— a small guard function called alongside the existing_check_if_input_columns_exist()check in bothunit_change_linearandunit_change_nonlinear. It raises a clearValueErrorif"f"appears ininput_column_names, explaining that"f"is reserved for the mechanism contribution and suggesting the user rename their input column.The
unit_change_nonlinear_input_onlyandunit_change_linear_input_onlyfunctions are not affected since they don't add the"f"column.Trade-offs
ValueErrorinstead of silent corruption: Although this is technically breaking for the (unlikely) case where a user already has code that passes"f"as an input column name, silent data corruption is far worse than an error. A clear error message makes the issue immediately actionable.Test Status
Added
test_given_input_column_named_f_when_evaluate_unit_change_with_mechanism_then_raises_value_errorcovering bothunit_change_linearandunit_change_nonlinear.CI will run the full test suite. No tests were broken by this change (existing tests all use
"A","B"as column names, none use"f"as an input column).