Skip to content

[Repo Assist] test: verify fit_estimator=False reuses cached estimator#1555

Draft
github-actions[bot] wants to merge 1 commit into
mainfrom
repo-assist/test-fit-estimator-false-reuse-4a10bf6219054b3e
Draft

[Repo Assist] test: verify fit_estimator=False reuses cached estimator#1555
github-actions[bot] wants to merge 1 commit into
mainfrom
repo-assist/test-fit-estimator-false-reuse-4a10bf6219054b3e

Conversation

@github-actions
Copy link
Copy Markdown
Contributor

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

Summary

Adds test_fit_estimator_false_reuses_cached_estimator to TestCausalModel, closing a coverage gap in the fit_estimator=False API path of CausalModel.estimate_effect().

Motivation

The existing test_causal_estimator_cache test only verifies that get_estimator() returns the correct object after fitting. It does not verify the full round-trip:

Call estimate_effect(fit_estimator=False) → confirm the cached estimator is reused without re-instantiation → confirm the returned estimate is identical (for deterministic estimators).

The fit_estimator=False path 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

  1. After estimate_effect(fit_estimator=True) (default), the estimator is stored in _estimator_cache.
  2. A subsequent estimate_effect(fit_estimator=False) on the same data retrieves the same object (verified via Python is identity).
  3. For backdoor.linear_regression (deterministic), both calls produce identical estimate values (verified via pytest.approx).

Test Status

tests/test_causal_model.py::TestCausalModel::test_fit_estimator_false_reuses_cached_estimator PASSED

Full test_causal_model.py run: 15 passed, 1 failed — the only failure is the pre-existing test_graph_input_nx which requires the optional pygraphviz dependency not installed in CI.

black --check and flake8 report no new issues in the added code.

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

…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>
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

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_regression estimator cache path across two estimate_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,
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant