Skip to content

[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
mainfrom
repo-assist/fix-unit-change-f-column-collision-55fdbb054301984d
Draft

github-actions[bot] wants to merge 1 commit into
mainfrom
repo-assist/fix-unit-change-f-column-collision-55fdbb054301984d

Conversation

@github-actions

Copy link
Copy Markdown
Contributor

🤖 This PR was created by Repo Assist, an automated AI assistant.

Problem

unit_change_linear and unit_change_nonlinear append a column named "f" to the output DataFrame to hold the mechanism's contribution. If the caller passes input_column_names that 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 name comment acknowledging this issue.

Root Cause

# unit_change_linear (line ~156 before fix)
contribution_df = pd.DataFrame(contribution_input, columns=input_column_names)
contribution_df["f"] = contribution_mechanism  # TODO: Handle the case where 'f' is an input column name

If "f" is in input_column_names, contribution_df["f"] already exists and gets overwritten by contribution_mechanism.

Fix

Added _check_no_reserved_column_name() — a small guard function called alongside the existing _check_if_input_columns_exist() check in both unit_change_linear and unit_change_nonlinear. It raises a clear ValueError if "f" appears in input_column_names, explaining that "f" is reserved for the mechanism contribution and suggesting the user rename their input column.

The unit_change_nonlinear_input_only and unit_change_linear_input_only functions are not affected since they don't add the "f" column.

Trade-offs

  • Raising a ValueError instead 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.
  • The fix is minimal — no new dependencies, no API surface change for normal usage.

Test Status

Added test_given_input_column_named_f_when_evaluate_unit_change_with_mechanism_then_raises_value_error covering both unit_change_linear and unit_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).

Generated by 🌈 Repo Assist, see workflow run. Learn more.

To install this agentic workflow, run

gh aw add githubnext/agentics/workflows/repo-assist.md@11c9a2c442e519ff2b427bf58679f5a525353f76

…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 branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

0 participants