Skip to content

[Repo Assist] fix: preserve mediation confounders and no_directed_path in IdentifiedEstimand.__deepcopy__#1548

Draft
github-actions[bot] wants to merge 1 commit into
mainfrom
repo-assist/fix-identified-estimand-deepcopy-20260527-095e42d1db788ba2
Draft

[Repo Assist] fix: preserve mediation confounders and no_directed_path in IdentifiedEstimand.__deepcopy__#1548
github-actions[bot] wants to merge 1 commit into
mainfrom
repo-assist/fix-identified-estimand-deepcopy-20260527-095e42d1db788ba2

Conversation

@github-actions
Copy link
Copy Markdown
Contributor

🤖 This is an automated PR from Repo Assist.

Problem

IdentifiedEstimand.__deepcopy__ was silently dropping three fields:

Field Present in constructor Present in __deepcopy__
mediation_first_stage_confounders
mediation_second_stage_confounders
no_directed_path

copy.deepcopy(estimand) is called in many places (refuters, TwoStageRegressionEstimator, CausalEstimator). Any time a NDE/NIE estimand was deep-copied, the mediation confounders were lost and no_directed_path was reset to its default (False). This could produce silently incorrect results in mediation analysis.

Key call sites affected:

  • causal_refuters/placebo_treatment_refuter.py
  • causal_refuters/random_common_cause.py
  • causal_refuters/dummy_outcome_refuter.py
  • causal_estimators/two_stage_regression_estimator.py (line 141: nde_target_estimand = copy.deepcopy(...))
  • causal_estimator.py

Fix

Added the three missing fields to IdentifiedEstimand.__deepcopy__ in dowhy/causal_identifier/identified_estimand.py.

Tests

Added two regression tests to tests/causal_identifiers/test_auto_identifier.py:

  1. test_deepcopy_preserves_all_fields — verifies that a full NDE estimand (with mediation confounders) is faithfully deep-copied.
  2. test_deepcopy_preserves_no_directed_path_flag — verifies that no_directed_path=True survives deep copy.

Test Status

tests/causal_identifiers/test_auto_identifier.py::test_auto_identify_identifies_no_directed_path PASSED
tests/causal_identifiers/test_auto_identifier.py::test_deepcopy_preserves_all_fields PASSED
tests/causal_identifiers/test_auto_identifier.py::test_deepcopy_preserves_no_directed_path_flag PASSED
136 passed, 11 warnings (full causal_identifiers suite)

No new lint errors introduced (the C901 on __str__ is pre-existing).

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

…dEstimand.__deepcopy__

The __deepcopy__ method of IdentifiedEstimand was missing three fields:
- mediation_first_stage_confounders
- mediation_second_stage_confounders
- no_directed_path

These are set during NDE/NIE identification. The bug caused them to be lost
when estimands are deep-copied (e.g. in refuters, TwoStageRegressionEstimator),
which could silently produce incorrect results in mediation analysis.

Adds two regression tests for the fixed behaviour.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

automation bug Something isn't working repo-assist

Projects

None yet

Development

Successfully merging this pull request may close these issues.

0 participants