[Repo Assist] fix: raise ValueError in estimate_effect() when identified estimand is None#1554
Draft
github-actions[bot] wants to merge 1 commit into
Conversation
…s None Previously, calling estimate_effect() with a method whose estimand is None (e.g. 'iv.instrumental_variable' when no instruments are in the graph) would silently return a CausalEstimate with value=None, with only a logger.error message. Callers had no programmatic indication that identification failed. This replaces the silent return with a ValueError that includes a descriptive message explaining which identifier failed and why, matching the contract expected by users (per issue #1551). Closes #1551 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
This was referenced May 31, 2026
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 PR from Repo Assist, an AI assistant for this repository.
Closes #1551
Root Cause
estimate_effect()incausal_estimator.py(lines 746–750) had a silent failure path: whenidentified_estimand.estimands[identifier_name]isNone(which happens when identification fails — e.g. callingiv.instrumental_variablebut the graph contains no instruments), the function logged alogger.errormessage and returned aCausalEstimate(value=None). Callers received no programmatic signal that something went wrong.Fix
Replace the silent return with a
ValueErrorthat includes a descriptive message:Why
ValueErrorand not a different exception? The call is invalid because the chosen method cannot be applied given the graph — the identifier name ("iv") does not correspond to a valid estimand. This is a value/argument error, consistent with howInstrumentalVariableEstimator.fit()andTwoStageRegressionEstimator.fit()handle similar invalid configurations.Note: This is different from the
no_directed_pathbranch just above, which correctly returnsCausalEstimate(value=0)because "no causal effect" is a meaningful, valid result. ANoneestimand means identification itself failed.Relationship to #1521 / PR #1520
PR #1520 (by
@abhiprd2000, who also filed #1551) fixes theivbranch ofTwoStageRegressionEstimator.fit()to raiseValueErrorwhen no instruments are present. This PR fixes the same class of issue one level up in the call stack — in the sharedestimate_effect()function that wraps all estimators — so that all estimators benefit regardless of their internal implementation.Changes
dowhy/causal_estimator.py: replace silentreturn CausalEstimate(None)withraise ValueError(3 lines changed)tests/causal_estimators/test_instrumental_variable_estimator.py: add regression testtest_estimate_effect_raises_when_iv_estimand_is_nonethat exercises the exact scenario from the issue reportTest Status
identified_estimand.estimands["iv"] is None, which occurs whennum_instruments=0inlinear_dataset(confirmed by tracingauto_identifier.py:291)estimate_effect()python3 -m py_compilepasses on both changed files