Skip to content

Commit 2f95353

Browse files
committed
Strengthen R0/R1 regression tests per CI feedback
CI AI review on #435: - P2: exp_p / exp_ci returned from safe_inference() were unused (F841). Extended event-study test to assert p_value and conf_int match safe_inference output too, not just t_stat. The safe_inference contract is joint NaN propagation across the full inference tuple, so testing all three jointly is the right invariant. - P3: placebo test only checked 'at least one finite entry', so a silent path-drop on the replicate-weight placebo branch could pass. Added explicit assertions that both (0,1,1,1) and (0,1,0,0) are present in res.path_placebo_event_study before checking SE/inference.
1 parent 44c4f69 commit 2f95353

1 file changed

Lines changed: 17 additions & 5 deletions

File tree

tests/test_chaisemartin_dhaultfoeuille.py

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9998,12 +9998,20 @@ def test_paths_of_interest_replicate_weight_per_path_se_finite(self):
99989998
for vals in entry["horizons"].values():
99999999
if vals["n_obs"] > 0 and np.isfinite(vals["se"]) and np.isfinite(vals["effect"]):
1000010000
exp_t, exp_p, exp_ci = safe_inference(vals["effect"], vals["se"], df=final_df)
10001-
matches = vals["t_stat"] == exp_t or (
10001+
t_matches = vals["t_stat"] == exp_t or (
1000210002
np.isnan(vals["t_stat"]) and np.isnan(exp_t)
1000310003
)
10004-
assert matches, (
10005-
"Per-path t_stat does not match safe_inference at the "
10006-
f"final df_survey={final_df} — refresh did not propagate"
10004+
p_matches = vals["p_value"] == exp_p or (
10005+
np.isnan(vals["p_value"]) and np.isnan(exp_p)
10006+
)
10007+
ci_matches = vals["conf_int"] == exp_ci or all(
10008+
np.isnan(a) == np.isnan(b)
10009+
for a, b in zip(vals["conf_int"], exp_ci, strict=True)
10010+
)
10011+
assert t_matches and p_matches and ci_matches, (
10012+
"Per-path inference fields do not match safe_inference at "
10013+
f"final df_survey={final_df} — refresh did not propagate "
10014+
"(t/p/conf_int must update jointly per safe_inference contract)"
1000710015
)
1000810016

1000910017
@pytest.mark.slow
@@ -10052,8 +10060,12 @@ def test_paths_of_interest_survey_design_placebo_replicate_weight(self):
1005210060
L_max=3,
1005310061
survey_design=sd,
1005410062
)
10055-
# Sanity-check: placebos for at least one requested path are populated.
10063+
# Both requested paths must be present in the placebo surface —
10064+
# a regression that silently drops one requested path would slip
10065+
# through an "at least one finite entry" check.
1005610066
assert res.path_placebo_event_study is not None
10067+
assert (0, 1, 1, 1) in res.path_placebo_event_study
10068+
assert (0, 1, 0, 0) in res.path_placebo_event_study
1005710069
any_finite_placebo = False
1005810070
for entry in res.path_placebo_event_study.values():
1005910071
for vals in entry.values():

0 commit comments

Comments
 (0)