Skip to content

[Repo Assist] fix(bootstrap_refuter): fix 3 bugs in categorical/integer variable perturbation - #1730

Draft
github-actions[bot] wants to merge 1 commit into
mainfrom
repo-assist/fix-bootstrap-refuter-categorical-20260802-1c9aa96e45015404
Draft

[Repo Assist] fix(bootstrap_refuter): fix 3 bugs in categorical/integer variable perturbation#1730
github-actions[bot] wants to merge 1 commit into
mainfrom
repo-assist/fix-bootstrap-refuter-categorical-20260802-1c9aa96e45015404

Conversation

@github-actions

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

Copy link
Copy Markdown
Contributor

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

Three bugs in _refute_once() in dowhy/causal_refuters/bootstrap_refuter.py affecting any run that sets required_variables (i.e. uses the chosen_variables path):

Bug 1 — Integer dtype check evaluates incorrectly (line 113)

# Before (broken): Python evaluates "float" or "int" as "float" (truthy short-circuit)
if ("float" or "int") in new_data[variable].dtype.name:

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

`("float" or "int")` is a valid Python expression but evaluates to `"float"`. Integer dtypes (`int32`, `int64`, `uint8`, ...) do not contain `"float"`, so integer common-cause columns silently received no noise during refutationthe refutation was meaningless.

## Bug 2 — `NameError` in the category branch (line 129)

`probs` was only defined inside `elif "bool"`. If the first categorical variable processed did not come after a boolean one, reaching `elif "category"` raised:

```
NameError: name 'probs' is not defined

Fix: define probs = np.random.uniform(0, 1, sample_size) at the start of the elif "category" block.

Bug 3 — 2-arg np.where + discarded astype (lines 129–130)

# Before: np.where with 2 args raises ValueError
new_data[variable] = np.where(probs < probability_of_change, changed_data)
# Also: astype returns a new Series, so this is a no-op:
new_data[variable].astype("category")

# After (correct):
new_data[variable] = np.where(probs < probability_of_change, changed_data, new_data[variable])
new_data[variable] = new_data[variable].astype("category")

np.where(cond, x) with only 2 positional args raises ValueError: either both or neither of x and y should be given. The 3rd argument (the "keep-original" array) was missing. Additionally, Series.astype() returns a new object and was not assigned back, leaving the dtype unchanged.

Tests

Two new regression tests in tests/causal_refuters/test_bootstrap_refuter.py:

Test What it checks
test_integer_column_receives_noise Integer dtype columns are actually perturbed (Bug 1)
test_categorical_column_no_crash Category branch completes without NameError or ValueError (Bugs 2 & 3)

Test Status

black --checkisort --checkflake8 — pre-existing E501 in test file unchanged, no new errors introduced.

CI blocked pending maintainer approval of bot PR — tests could not be executed in this environment (no Poetry/venv), but all fixes have been verified by code inspection against the exact error paths described above.

Note: Bug 1 and the astype part of Bug 3 were also identified in PR #1633. This PR fixes all three bugs in one pass and supersedes #1633.

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

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

…e perturbation

Three bugs in _refute_once() in bootstrap_refuter.py that affect the
required_variables / chosen_variables path:

Bug 1 (integer dtype check, line 113):
  Before: ('float' or 'int') in dtype.name
  This is valid Python but evaluates as 'float' in dtype.name only,
  because 'float' is truthy. Integer dtypes (int32, int64) never
  contain 'float', so integer columns silently received no noise.
  After:  'float' in dtype.name or 'int' in dtype.name

Bug 2 (NameError in category branch, line 129):
  probs was only defined inside elif 'bool', so reaching elif 'category'
  without first having a bool-typed variable raised NameError: probs.
  Fix: define probs at the top of the category branch.

Bug 3 (2-arg np.where + discarded astype, lines 129-130):
  np.where(condition, x) with only 2 args raises ValueError (both or
  neither of x and y must be given). Should be np.where(cond, x, y).
  Additionally, Series.astype() returns a new Series and never mutates
  in place; the result was not assigned back.
  Fix: pass new_data[variable] as the 3rd arg and assign the result.

Adds two regression tests covering integer-column noise and
categorical-column perturbation end-to-end.

Note: Bug 1 and the astype fix (Bug 3 partial) were also identified in
PR #1633; this PR supersedes that one with all three fixes.

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 added automation bug Something isn't working repo-assist labels Aug 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

automation bug Something isn't working repo-assist

Projects

None yet

Development

Successfully merging this pull request may close these issues.

0 participants