[Repo Assist] fix: use string key for column lookup in conditional_MI (fixes KeyError with multi-char column names)#1455
Open
github-actions[bot] wants to merge 1 commit intomainfrom
Conversation
When x or y are string column names passed to conditional_MI, calling list(x) iterates over individual characters (e.g. 'Foo' becomes ['F','o','o']) rather than treating the string as a key. Fix: use data[x] and data[y] (Series lookup) instead of data[list(x)] and data[list(y)] (multi-key DataFrame lookup). Add tests to cover multi-character column names in GraphRefuter. Closes #949 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
41 tasks
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 is an automated fix from Repo Assist.
Closes #949
Root Cause
In
dowhy/utils/cit.py,conditional_MIuseddata[list(x)]anddata[list(y)]to access columns. Whenxandyare string column names (as they always are when called fromGraphRefuter.conditional_mutual_information),list(x)iterates over individual characters:This means any column name longer than one character would trigger the error.
Fix
Change
data[list(x)]→data[x]anddata[list(y)]→data[y], which performs standard single-column Series lookup. This is correct sincexandyare scalar string column names.Trade-offs
zip/ format-string logic expects).Test Status
New tests added in
tests/causal_refuters/test_graph_refuter.py:test_conditional_mi_multi_char_column_names— regression test confirming multi-char names no longer raiseKeyErrortest_conditional_mi_single_char_column_names— ensures single-char names still worktest_graph_refuter_with_multi_char_columns— end-to-endrefute_modelcall with multi-char columnsAll new tests pass locally. Formatting (
black,isort) and linting (flake8) pass on changed files.