[Repo Assist] fix(bootstrap_refuter): fix 3 bugs in categorical/integer variable perturbation - #1730
Draft
github-actions[bot] wants to merge 1 commit into
Conversation
…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>
78 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 PR was created by Repo Assist, an automated AI assistant.
Three bugs in
_refute_once()indowhy/causal_refuters/bootstrap_refuter.pyaffecting any run that setsrequired_variables(i.e. uses thechosen_variablespath):Bug 1 — Integer dtype check evaluates incorrectly (line 113)
Fix: define
probs = np.random.uniform(0, 1, sample_size)at the start of theelif "category"block.Bug 3 — 2-arg
np.where+ discardedastype(lines 129–130)np.where(cond, x)with only 2 positional args raisesValueError: 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_integer_column_receives_noisetest_categorical_column_no_crashNameErrororValueError(Bugs 2 & 3)Test Status
black --check✅isort --check✅flake8— 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
astypepart of Bug 3 were also identified in PR #1633. This PR fixes all three bugs in one pass and supersedes #1633.