Skip to content

Commit ae4eac1

Browse files
feat(smart): Sprint-B coverage in assumption_audit + pub_ready + fail-loud tests
Two Smart-tool gaps for the Sprint-B causal modules, closed after a fresh-eyes code review of this session's work. 1. sp.pub_ready — single-result acceptance + array/Series guard Pre-fix, sp.pub_ready(my_causal_result) crashed with "'CausalResult' object is not iterable". Now auto-wraps bare scalars; numpy.ndarray and pandas.Series pass through the iterable guard (so pub_ready(np.array([r1, r2])) iterates elements rather than wrapping the whole array). The truthy check was replaced by an explicit len() to avoid the "ambiguous truth value" error on ndarray. 2. sp.assumption_audit — Sprint-B method-specific audits Detection now reads ``.method`` + ``model_info['model_type']`` + ``model_info['estimator']``; plus class-name check for PrincipalStratResult. Seven new _audit_* functions fire method- specific assumption checks: - proximal: bridge form, proxy order condition, first-stage F - msm: sw_mean drift, positivity (sw_max), exposure target, sequential exchangeability reminder - principal_strat: monotonicity violation fraction, stratum proportions, principal ignorability (only under the principal_score method) - g_computation: outcome-model correctness reminder, bootstrap health - front_door: mediator family, no-direct-path reminder, no unmeasured M-Y confounder reminder - mediate_interventional: decomposition identity IIE+IDE=Total with explicit fallback when keys are missing (no vacuous pass), treatment-induced-confounder listing - mediate (natural): cross-world independence reminder + bootstrap failure-rate tracking BUG FIX — keyword-substring leak: pre-fix, naive substring match triggered Panel ('fe'/'re') and IV ('iv'/'2sls') checks inside "Proximal Causal Inference (linear 2SLS)" because the short tokens appear as substrings of "inference" and "2sls". Now uses word- boundary regex + Sprint-B-first dispatch, so classical branches only run when NO Sprint-B branch matched. BUG FIX — dispatch collision: method strings containing BOTH 'interventional mediation' and 'causal mediation' would double-fire both branches. Natural-mediation branch is now guarded by ``not sprint_b_matched``. 3. Test coverage - tests/test_smart_tools_sprint_b.py (15 tests): pub_ready scalar equivalence, ndarray support, None/empty; assumption_audit for each Sprint-B method with explicit forbidden-names leak check; review-round-2 regression tests (no vacuous pass, no double firing, bootstrap failure-rate check, ndarray auto-wrap). - tests/test_diagnose_batteries_sprint_b.py: - strengthened test_mediate_wald_pvalue to use scipy.stats.norm.sf as independent ground truth plus a null-effect cross-check (catches sign errors the self-circular version missed); - new test_battery_proximal_order_condition_check_directly constructs a hand-crafted CausalResult with k_z<k_w so the previously-dead battery code path is actually tested. Regression: 180/180 Sprint-B tests pass; 50/50 broader smart-workflow regression tests pass. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 7d6ce12 commit ae4eac1

4 files changed

Lines changed: 912 additions & 33 deletions

File tree

0 commit comments

Comments
 (0)