Skip to content

fix: raise ValueError when no valid estimand is identified instead of silent None return#1552

Open
abhiprd2000 wants to merge 4 commits into
py-why:mainfrom
abhiprd2000:fix/causal-estimator-silent-none
Open

fix: raise ValueError when no valid estimand is identified instead of silent None return#1552
abhiprd2000 wants to merge 4 commits into
py-why:mainfrom
abhiprd2000:fix/causal-estimator-silent-none

Conversation

@abhiprd2000
Copy link
Copy Markdown
Contributor

Summary

estimate_effect() silently returns None when identified_estimand.estimands[identifier_name] is None, logging an error but not raising. Users get no indication that identification failed.

Fix

Replace the silent return CausalEstimate(None, ...) with raise ValueError(error_msg) including the identifier name for easier debugging.

Impact

  • callers now get a clear ValueError instead of silent None
  • error message includes the identifier name to help users debug their graph or method choice
  • adds a regression test to prevent future recurrence

Fixes #1551
Signed-off-by: abhiprd2000

…f silent None return

Signed-off-by: abhiprd2000 <8292aniarc@gmail.com>
Signed-off-by: abhiprd2000 <8292aniarc@gmail.com>
@abhiprd2000
Copy link
Copy Markdown
Contributor Author

Hi @emrekiciman,

follow-up to your suggestion on #1520. Fix and regression test included.

Signed-off-by: abhiprd2000 <8292aniarc@gmail.com>
@abhiprd2000
Copy link
Copy Markdown
Contributor Author

abhiprd2000 commented May 30, 2026

Hi @emrekiciman,

Noticed github-actions bot also filed a draft #1554 for the same fix. Mine includes an end-to-end test via CausalModel as we discussed in #1520. Happy to adjust anything if needed.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR makes estimate_effect() fail loudly when identification did not produce a valid estimand for the requested identifier, by raising a ValueError instead of returning a CausalEstimate with a None value. This aligns behavior with the expectation that a missing estimand indicates identification failure rather than a valid “no effect” result.

Changes:

  • Raise a ValueError (with identifier name included) when identified_estimand.estimands[identifier_name] is None.
  • Add a regression test covering the missing-estimand case for iv.instrumental_variable.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
dowhy/causal_estimator.py Replaces the silent CausalEstimate(None, …) return with a logged ValueError when the estimand is missing.
tests/test_causal_estimator.py Adds a regression test asserting estimate_effect() raises ValueError for missing IV estimand.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread tests/test_causal_estimator.py Outdated
Comment thread tests/test_causal_estimator.py
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Signed-off-by: Abhimanyu Prasad <8292aniarc@gmail.com>
Copy link
Copy Markdown
Member

@amit-sharma amit-sharma left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks @abhiprd2000 This looks good

@amit-sharma
Copy link
Copy Markdown
Member

@all-contributors add @abhiprd2000 for code

@allcontributors
Copy link
Copy Markdown
Contributor

@amit-sharma

I've put up a pull request to add @abhiprd2000! 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

estimate_effect() silently returns None when no valid estimand is identified

3 participants