[Repo Assist] fix(bootstrap_refuter): correct dtype check and discard-proof category astype#1633
Open
github-actions[bot] wants to merge 2 commits into
Conversation
…nment
Two bugs in _refute_once():
1. Line 113: "('float' or 'int') in dtype.name" always evaluates to
"'float' in dtype.name" because Python's 'or' returns the first
truthy operand. As a result, integer columns (int32, int64, uint8,
etc.) were silently skipped — no noise was added even though the
intent was to perturb both float and int columns.
Fix: "'float' in dtype.name or 'int' in dtype.name"
2. Line 130: "new_data[variable].astype('category')" discards its
return value; the column dtype is never actually changed.
Fix: assign the result back to new_data[variable].
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 Jul 2, 2026
…ategory astype bugs
Add two regression tests to TestBootstrapRefuterDtypeBugs:
1. test_integer_column_receives_noise: directly calls _refute_once with an int64
common-cause column to confirm no crash and a valid float estimate is returned.
Before the fix ('float' or 'int') reduced to 'float', silently skipping int columns.
2. test_integer_required_variables_end_to_end: end-to-end test using integer common
causes with required_variables=["W0","W1"] to exercise the full bootstrap_refuter
path and verify the refuted effect is finite.
These complement the production fix in dowhy/causal_refuters/bootstrap_refuter.py.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Contributor
Author
|
Commit pushed:
|
emrekiciman
marked this pull request as ready for review
July 7, 2026 07:06
This was referenced Jul 8, 2026
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.
Summary
Two silent bugs in
_refute_once()indowhy/causal_refuters/bootstrap_refuter.py:Bug 1 — Integer columns receive no noise (line 113)
Python evaluates
"float" or "int"as"float"(the first truthy operand), so the condition reduces to"float" in dtype.name. Integer dtypes likeint32,int64,uint8do not contain the substring"float", so they always fall through — no noise is ever added to integer columns, silently corrupting the refutation for users whose adjustment-set variables are integers.Verified with Python:
Bug 2 — Category cast result discarded (line 130)
Series.astype()returns a new Series; it never mutates in place. The original line left the column dtype unchanged after the np.where assignment.Impact
Both bugs are in the
chosen_variablespath, which is exercised wheneverrequired_variablesis set (e.g.required_variables=3orrequired_variables=["W0","W1"]). Integer common-cause columns are common in practice (e.g. binary treatment flags stored as int, discretized covariates).Test Status
black --check✅ (unchanged)isort --check✅ (unchanged)flake8— pre-existing E501/F401 warnings on unrelated lines; no new errors introduced