[Repo Assist] fix: preserve mediation confounders and no_directed_path in IdentifiedEstimand.__deepcopy__#1548
Draft
github-actions[bot] wants to merge 1 commit into
Conversation
…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>
This was referenced May 28, 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.
Problem
IdentifiedEstimand.__deepcopy__was silently dropping three fields:__deepcopy__mediation_first_stage_confoundersmediation_second_stage_confoundersno_directed_pathcopy.deepcopy(estimand)is called in many places (refuters,TwoStageRegressionEstimator,CausalEstimator). Any time a NDE/NIE estimand was deep-copied, the mediation confounders were lost andno_directed_pathwas reset to its default (False). This could produce silently incorrect results in mediation analysis.Key call sites affected:
causal_refuters/placebo_treatment_refuter.pycausal_refuters/random_common_cause.pycausal_refuters/dummy_outcome_refuter.pycausal_estimators/two_stage_regression_estimator.py(line 141:nde_target_estimand = copy.deepcopy(...))causal_estimator.pyFix
Added the three missing fields to
IdentifiedEstimand.__deepcopy__indowhy/causal_identifier/identified_estimand.py.Tests
Added two regression tests to
tests/causal_identifiers/test_auto_identifier.py:test_deepcopy_preserves_all_fields— verifies that a full NDE estimand (with mediation confounders) is faithfully deep-copied.test_deepcopy_preserves_no_directed_path_flag— verifies thatno_directed_path=Truesurvives deep copy.Test Status
No new lint errors introduced (the C901 on
__str__is pre-existing).