Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[Repo Assist] fix(sensitivity): robust frac_strength init and early validation in LinearSensitivityAnalyzer#1705

Draft
github-actions[bot] wants to merge 1 commit into
mainpy-why/dowhy:mainfrom
repo-assist/fix-linear-sensitivity-frac-init-20260723-ac5748a4d4e1b254py-why/dowhy:repo-assist/fix-linear-sensitivity-frac-init-20260723-ac5748a4d4e1b254Copy head branch name to clipboard
Draft

[Repo Assist] fix(sensitivity): robust frac_strength init and early validation in LinearSensitivityAnalyzer#1705
github-actions[bot] wants to merge 1 commit into
mainpy-why/dowhy:mainfrom
repo-assist/fix-linear-sensitivity-frac-init-20260723-ac5748a4d4e1b254py-why/dowhy:repo-assist/fix-linear-sensitivity-frac-init-20260723-ac5748a4d4e1b254Copy head branch name to clipboard

Conversation

@github-actions

Copy link
Copy Markdown
Contributor

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

Problem

Two bugs in LinearSensitivityAnalyzer.__init__ and check_sensitivity():

Bug 1 — np.ndarray input silently ignored → AttributeError

The old type-list check if type(frac_strength_treatment) in [int, list, float] excluded np.ndarray. Passing effect_fraction_on_treatment=np.array([1.0, 2.0]) left self.frac_strength_treatment unset, so check_sensitivity() raised:

AttributeError: 'LinearSensitivityAnalyzer' object has no attribute 'frac_strength_treatment'

Bug 2 — benchmark_common_causes + frac_strength=None → unhelpful AttributeError

Same root cause: explicit None fell through the type check, so self.frac_strength_treatment was never set. Result: an opaque AttributeError instead of a clear ValueError.

Fix

  • Replace the brittle type-list check with frac_strength is not None else None — handles int, float, list, np.ndarray, and None uniformly.
  • Add explicit ValueError early in check_sensitivity() when benchmark_common_causes is set but either frac param is None.

Relation to PR #1689

PR #1689 fixes crashes inside check_sensitivity() after the benchmarking loop (no-benchmark guard + scalar-iterable fix). This PR fixes the initialization so valid np.ndarray inputs work and None+benchmarking gives a clear early error. These are orthogonal.

Tests

Two new regression tests:

  • test_linear_sensitivity_numpy_array_frac_strength_does_not_raise: numpy array frac → no AttributeError
  • test_linear_sensitivity_benchmark_with_none_frac_raises_value_error: benchmark + frac=None → clear ValueError

Test Status

  • ✅ Hard flake8 errors (E9,F63,F7,F82): none
  • black --check compliant
  • isort --check compliant

Generated by 🤖 Repo Assist, see workflow run.

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

…ensitivityAnalyzer

Two bugs in LinearSensitivityAnalyzer.__init__ and check_sensitivity():

Bug 1 — np.ndarray input silently ignored

  if type(frac_strength_treatment) in [int, list, float]:
      self.frac_strength_treatment = np.array(frac_strength_treatment)

type(np.array([1, 2])) is np.ndarray, not in [int, list, float], so
self.frac_strength_treatment was never set. Downstream code at
check_sensitivity():268 (self.frac_strength_treatment * ...) then raised
AttributeError: 'LinearSensitivityAnalyzer' object has no attribute
'frac_strength_treatment'.

This surfaces when a caller passes effect_fraction_on_treatment as a numpy
array (e.g. effect_fraction_on_treatment=np.array([1.0, 2.0])).

Bug 2 — benchmark_common_causes + frac_strength=None raises AttributeError

When benchmark_common_causes is provided but frac_strength_treatment=None
(explicitly passed), self.frac_strength_treatment was never set (same
type-check miss), so the benchmarking loop crashed with an unhelpful
AttributeError instead of a clear ValueError.

Fix:
- Replace the type-list check with frac_strength is not None else None,
  which handles int, float, list, np.ndarray, and None uniformly.
- Add an explicit ValueError at the top of check_sensitivity() when
  benchmark causes are requested without the required frac_strength params.

Regression tests added:
- test_linear_sensitivity_numpy_array_frac_strength_does_not_raise
- test_linear_sensitivity_benchmark_with_none_frac_raises_value_error

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

Copy link
Copy Markdown
Contributor Author

🤖 This is an automated note from Repo Assist.

Heads-up: this PR is a duplicate of #1704. Both were created in the same run (2026-07-23) and fix the identical two bugs in LinearSensitivityAnalyzer:

  • Bug 1: np.ndarray frac_strength silently ignored → AttributeError
  • Bug 2: benchmark_common_causes + frac_strength=None → opaque AttributeError instead of clear ValueError

The code changes and tests are equivalent. I'd recommend maintainers review #1704 and close this one (or vice versa — either is fine). Apologies for the duplication.

Generated by 🤖 Repo Assist, see workflow run.

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

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

Morty Proxy This is a proxified and sanitized view of the page, visit original site.