[Repo Assist] test: verify fit_estimator=False reuses cached estimator#1555
Draft
github-actions[bot] wants to merge 1 commit into
Draft
[Repo Assist] test: verify fit_estimator=False reuses cached estimator#1555github-actions[bot] wants to merge 1 commit into
github-actions[bot] wants to merge 1 commit into
Conversation
…tting Add test_fit_estimator_false_reuses_cached_estimator to TestCausalModel to explicitly verify the fit_estimator=False API path in CausalModel.estimate_effect(): - After a first call (fit_estimator=True, default), the estimator is stored in the cache via _estimator_cache[method_name]. - A subsequent call with fit_estimator=False must retrieve the same object from cache (verified via identity check). - For deterministic estimators (linear_regression), both calls must produce identical estimate values (verified via pytest.approx). The existing test_causal_estimator_cache only checks that get_estimator() returns the same object; this new test closes the gap by exercising the full fit_estimator=False round-trip through estimate_effect(). Signed-off-by: Repo Assist <noreply@github.com> Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
57 tasks
Contributor
There was a problem hiding this comment.
Pull request overview
Adds a regression test for CausalModel.estimate_effect(fit_estimator=False) to verify cached estimator reuse in the causal model estimation workflow.
Changes:
- Adds
test_fit_estimator_false_reuses_cached_estimator. - Exercises the
backdoor.linear_regressionestimator cache path across twoestimate_effect()calls. - Compares estimator object identity and deterministic estimate values.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+736
to
+743
| # Second call with fit_estimator=False must reuse the cached estimator. | ||
| estimate2 = model.estimate_effect( | ||
| identified_estimand, | ||
| method_name=method, | ||
| control_value=0, | ||
| treatment_value=1, | ||
| fit_estimator=False, | ||
| ) |
41 tasks
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 was created by Repo Assist, an automated AI assistant.
Summary
Adds
test_fit_estimator_false_reuses_cached_estimatortoTestCausalModel, closing a coverage gap in thefit_estimator=FalseAPI path ofCausalModel.estimate_effect().Motivation
The existing
test_causal_estimator_cachetest only verifies thatget_estimator()returns the correct object after fitting. It does not verify the full round-trip:The
fit_estimator=Falsepath is used in real workflows to evaluate a fitted model on new data (e.g., issue #484), and it was also the subject of issue #414. Testing it explicitly catches any regression where the estimator cache lookup is bypassed.What the new test checks
estimate_effect(fit_estimator=True)(default), the estimator is stored in_estimator_cache.estimate_effect(fit_estimator=False)on the same data retrieves the same object (verified via Pythonisidentity).backdoor.linear_regression(deterministic), both calls produce identical estimate values (verified viapytest.approx).Test Status
Full
test_causal_model.pyrun: 15 passed, 1 failed — the only failure is the pre-existingtest_graph_input_nxwhich requires the optionalpygraphvizdependency not installed in CI.black --checkandflake8report no new issues in the added code.