Skip to content

[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
repo-assist/fix-std-kappa-inference-20260325-520344f399f1753d
Open

[Repo Assist] fix: remove invalid [0] subscript on np.std() scalar in kappa auto-inference#1420
github-actions[bot] wants to merge 1 commit intomainfrom
repo-assist/fix-std-kappa-inference-20260325-520344f399f1753d

Conversation

@github-actions
Copy link
Contributor

🤖 This is an automated pull request from Repo Assist.

Root Cause

_infer_default_kappa_t() and _infer_default_kappa_y() in dowhy/causal_refuters/add_unobserved_common_cause.py each compute the standard deviation of treatment/outcome and immediately subscript the result with [0]:

# line 269
std_dev_t = np.std(t)[0]

# line 321
std_dev_y = np.std(y)[0]
```

`np.std()` applied to a pandas Series or single-column DataFrame returns a **scalar** numpy float. Subscripting a scalar raises:

```
IndexError: invalid index to scalar variable

This error fires whenever add_unobserved_common_cause is called with:

  • simulation_method="direct-simulation" (the default), and
  • confounders_effect_on_treatment="linear" or confounders_effect_on_outcome="linear", and
  • no explicit effect_strength_on_treatment / effect_strength_on_outcome is supplied (forcing auto-inference of kappa_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 in float():

std_dev_t = float(np.std(t))
std_dev_y = float(np.std(y))

This is correct: std_dev_t / std_dev_y are used purely as scalar multipliers (max_coeff = max(corrcoef_var_t) * std_dev_t), so a plain Python float is the right type regardless of pandas/numpy version.

Changes

  • dowhy/causal_refuters/add_unobserved_common_cause.py — two-character fix on lines 269 and 321
  • tests/causal_refuters/test_add_unobserved_common_cause.py — new regression test test_infer_default_kappa_linear_does_not_crash that exercises the auto-inference path

Test 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).

Generated by Repo Assist

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.

Generated by Repo Assist ·

To install this agentic workflow, run

gh aw add githubnext/agentics/workflows/repo-assist.md@b897c2f3e43bde9ff7923c8fa9211055b26e27cc

…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>
@emrekiciman emrekiciman marked this pull request as ready for review March 25, 2026 18:12
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