Skip to content

[Repo Assist] fix(bootstrap_refuter): correct dtype check and discard-proof category astype#1633

Open
github-actions[bot] wants to merge 2 commits into
mainfrom
repo-assist/fix-bootstrap-refuter-dtype-check-2026-07-02-543f534a340bc511
Open

[Repo Assist] fix(bootstrap_refuter): correct dtype check and discard-proof category astype#1633
github-actions[bot] wants to merge 2 commits into
mainfrom
repo-assist/fix-bootstrap-refuter-dtype-check-2026-07-02-543f534a340bc511

Conversation

@github-actions

@github-actions github-actions Bot commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

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

Summary

Two silent bugs in _refute_once() in dowhy/causal_refuters/bootstrap_refuter.py:

Bug 1 — Integer columns receive no noise (line 113)

# Before (broken)
if ("float" or "int") in new_data[variable].dtype.name:

Python evaluates "float" or "int" as "float" (the first truthy operand), so the condition reduces to "float" in dtype.name. Integer dtypes like int32, int64, uint8 do 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.

# After (correct)
if "float" in new_data[variable].dtype.name or "int" in new_data[variable].dtype.name:

Verified with Python:

>>> ("float" or "int") in "int64"
False   # bug: should be True
>>> "float" in "int64" or "int" in "int64"
True    # correct

Bug 2 — Category cast result discarded (line 130)

# Before (no-op)
new_data[variable].astype("category")

# After (correct)
new_data[variable] = new_data[variable].astype("category")

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_variables path, which is exercised whenever required_variables is set (e.g. required_variables=3 or required_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

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

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

…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>
…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>
@github-actions

github-actions Bot commented Jul 3, 2026

Copy link
Copy Markdown
Contributor Author

Commit pushed: a019e7a

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

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