[Repo Assist] fix: remove invalid [0] subscript on np.std() scalar in kappa auto-inference#1420
Open
github-actions[bot] wants to merge 1 commit intomainfrom
Conversation
…t_kappa_t/y np.std() applied to a pandas Series or DataFrame returns a scalar numpy float. Indexing that scalar with [0] raises: IndexError: invalid index to scalar variable This error surfaces whenever add_unobserved_common_cause is called with simulation_method='direct-simulation' and confounders_effect_on_treatment or confounders_effect_on_outcome set to 'linear' WITHOUT supplying an explicit effect_strength_on_treatment / effect_strength_on_outcome. Fix: wrap both calls in float() so the result is an unambiguous Python float regardless of pandas/numpy version interactions. Also adds a regression test (test_infer_default_kappa_linear_does_not_crash) that exercises this code path to prevent future regressions. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
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 pull request from Repo Assist.
Root Cause
_infer_default_kappa_t()and_infer_default_kappa_y()indowhy/causal_refuters/add_unobserved_common_cause.pyeach compute the standard deviation of treatment/outcome and immediately subscript the result with[0]:This error fires whenever
add_unobserved_common_causeis called with:simulation_method="direct-simulation"(the default), andconfounders_effect_on_treatment="linear"orconfounders_effect_on_outcome="linear", andeffect_strength_on_treatment/effect_strength_on_outcomeis supplied (forcing auto-inference ofkappa_t/kappa_y)Because all existing tests supply explicit effect strengths, this code path was never exercised and the bug went undetected.
Fix
Wrap both
np.std()calls infloat():This is correct:
std_dev_t/std_dev_yare used purely as scalar multipliers (max_coeff = max(corrcoef_var_t) * std_dev_t), so a plain Pythonfloatis the right type regardless of pandas/numpy version.Changes
dowhy/causal_refuters/add_unobserved_common_cause.py— two-character fix on lines 269 and 321tests/causal_refuters/test_add_unobserved_common_cause.py— new regression testtest_infer_default_kappa_linear_does_not_crashthat exercises the auto-inference pathTest Status
The new regression test directly targets the fixed code path. All existing tests are unaffected (they pass explicit kappa values and never reach
_infer_default_kappa_t/y).Note
🔒 Integrity filtering filtered 62 items
Integrity filtering activated and filtered the following items during workflow execution.
This happens when a tool call accesses a resource that does not meet the required integrity or secrecy level of the workflow.
list_pull_requests: has lower integrity than agent requires. The agent cannot read data with integrity below "approved".)list_pull_requests: has lower integrity than agent requires. The agent cannot read data with integrity below "approved".)list_pull_requests: has lower integrity than agent requires. The agent cannot read data with integrity below "approved".)list_pull_requests: has lower integrity than agent requires. The agent cannot read data with integrity below "approved".)list_pull_requests: has lower integrity than agent requires. The agent cannot read data with integrity below "approved".)list_pull_requests: has lower integrity than agent requires. The agent cannot read data with integrity below "approved".)list_issues: has lower integrity than agent requires. The agent cannot read data with integrity below "approved".)list_issues: has lower integrity than agent requires. The agent cannot read data with integrity below "approved".)list_issues: has lower integrity than agent requires. The agent cannot read data with integrity below "approved".)list_issues: has lower integrity than agent requires. The agent cannot read data with integrity below "approved".)list_issues: has lower integrity than agent requires. The agent cannot read data with integrity below "approved".)list_issues: has lower integrity than agent requires. The agent cannot read data with integrity below "approved".)list_issues: has lower integrity than agent requires. The agent cannot read data with integrity below "approved".)list_issues: has lower integrity than agent requires. The agent cannot read data with integrity below "approved".)list_issues: has lower integrity than agent requires. The agent cannot read data with integrity below "approved".)list_issues: has lower integrity than agent requires. The agent cannot read data with integrity below "approved".)