[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#1705github-actions[bot] wants to merge 1 commit intomainpy-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
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
…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>
66 tasks
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
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.
|
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 is created by Repo Assist, an automated AI assistant.
Problem
Two bugs in
LinearSensitivityAnalyzer.__init__andcheck_sensitivity():Bug 1 —
np.ndarrayinput silently ignored →AttributeErrorThe old type-list check
if type(frac_strength_treatment) in [int, list, float]excludednp.ndarray. Passingeffect_fraction_on_treatment=np.array([1.0, 2.0])leftself.frac_strength_treatmentunset, socheck_sensitivity()raised:Bug 2 —
benchmark_common_causes+frac_strength=None→ unhelpfulAttributeErrorSame root cause: explicit
Nonefell through the type check, soself.frac_strength_treatmentwas never set. Result: an opaqueAttributeErrorinstead of a clearValueError.Fix
frac_strength is not None else None— handlesint,float,list,np.ndarray, andNoneuniformly.ValueErrorearly incheck_sensitivity()whenbenchmark_common_causesis set but either frac param isNone.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 validnp.ndarrayinputs work andNone+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 → noAttributeErrortest_linear_sensitivity_benchmark_with_none_frac_raises_value_error: benchmark +frac=None→ clearValueErrorTest Status
E9,F63,F7,F82): noneblack --checkcompliantisort --checkcompliant