Skip to content

Commit b2bfdd0

Browse files
igerberclaude
andcommitted
Address PR #402 R8 review (1 P3, to_dict() docstring drift)
P3 doc drift: PR #402 R3 fixed llms-full.txt, R5 fixed the dataclass field docstrings, but HeterogeneousAdoptionDiDResults.to_dict() still described variance_formula as continuous-only ("pweight" / "survey_binder_tsl") and omitted the mass-point Wald-IV effective_dose_mean semantics. Three internal source-of-truth surfaces were now disagreeing about the same public result object's to_dict() output shape. Updated to_dict() docstring to enumerate all four variance_formula labels (pweight, survey_binder_tsl, pweight_2sls, survey_binder_tsl_2sls) and to describe the per-design effective_dose_mean semantics (continuous mean of D / D - d_lower vs mass-point weighted Wald-IV dose gap mean(D | Z=1, w) - mean(D | Z=0, w)). Mirrors the field-docstring contract from R5. Tests added (1 new, 95 total): - test_had_results_to_dict_docstring_matches_weighted_mass_point_contract: reads HeterogeneousAdoptionDiDResults.to_dict.__doc__ and asserts it enumerates all four variance_formula labels and the mass-point Wald-IV effective_dose_mean semantics. Mirrors the existing dataclass-field-docstring lock. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 4a24758 commit b2bfdd0

2 files changed

Lines changed: 51 additions & 2 deletions

File tree

diff_diff/had.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -483,9 +483,20 @@ def to_dict(self) -> Dict[str, Any]:
483483
``design_effect`` / ``sum_weights`` / ``weight_range`` +
484484
``n_strata`` / ``n_psu`` / ``df_survey`` (latter three
485485
``None`` on the ``weights=`` shortcut).
486-
- ``variance_formula``: ``"pweight"`` or ``"survey_binder_tsl"``.
486+
- ``variance_formula``: HAD-specific SE label, populated on BOTH
487+
continuous and mass-point designs (Phase 4.5 A / B):
488+
``"pweight"`` (continuous, weighted-robust CCT 2014 under
489+
``weights=``), ``"survey_binder_tsl"`` (continuous, Binder
490+
1983 TSL under ``survey_design=``), ``"pweight_2sls"``
491+
(mass-point, weighted 2SLS HC1/CR1 sandwich under ``weights=``),
492+
or ``"survey_binder_tsl_2sls"`` (mass-point, Binder 1983 TSL
493+
under ``survey_design=``). See the field docstring above for
494+
the full contract.
487495
- ``effective_dose_mean``: weighted denominator used by the
488-
beta-scale rescaling."""
496+
beta-scale rescaling - weighted ``mean(D)`` on
497+
``continuous_at_zero``, weighted ``mean(D - d_lower)`` on
498+
``continuous_near_d_lower``, or the weighted Wald-IV dose gap
499+
``mean(D | Z=1, w) - mean(D | Z=0, w)`` on ``mass_point``."""
489500
return {
490501
"att": self.att,
491502
"se": self.se,

tests/test_practitioner.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -730,6 +730,44 @@ def test_had_event_study_sup_t_snippet_uses_hc1_for_mass_point_survey_compatibil
730730
"fail at fit time on a mass-point panel."
731731
)
732732

733+
def test_had_results_to_dict_docstring_matches_weighted_mass_point_contract(self):
734+
# Parallel to the dataclass-field-docstring regression below:
735+
# PR #402 R8 P3 caught that HeterogeneousAdoptionDiDResults.to_dict()
736+
# docstring still described variance_formula as continuous-only
737+
# / "pweight" or "survey_binder_tsl", contradicting the field
738+
# docstrings (fixed in R5) and llms-full.txt (fixed in R3).
739+
# Lock the to_dict() docstring against drift back.
740+
from diff_diff.had import HeterogeneousAdoptionDiDResults
741+
742+
doc = HeterogeneousAdoptionDiDResults.to_dict.__doc__ or ""
743+
for label in (
744+
"pweight",
745+
"survey_binder_tsl",
746+
"pweight_2sls",
747+
"survey_binder_tsl_2sls",
748+
):
749+
assert label in doc, (
750+
f"HeterogeneousAdoptionDiDResults.to_dict() docstring "
751+
f"must enumerate the {label!r} variance_formula label - "
752+
f"weighted mass-point fits populate pweight_2sls / "
753+
f"survey_binder_tsl_2sls per had.py:3585-3629. The "
754+
f"to_dict() docstring is a public source-of-truth "
755+
f"surface and must match the field docstrings + "
756+
f"llms-full.txt HAD section."
757+
)
758+
# effective_dose_mean: must mention mass-point Wald-IV semantics.
759+
assert "mass_point" in doc or "mass-point" in doc, (
760+
"HeterogeneousAdoptionDiDResults.to_dict() docstring must "
761+
"describe the mass-point effective_dose_mean semantics; "
762+
"weighted mass-point fits populate it as the weighted "
763+
"Wald-IV dose gap per had.py:3642-3660."
764+
)
765+
assert "Wald-IV" in doc or "Z=1" in doc, (
766+
"HeterogeneousAdoptionDiDResults.to_dict() docstring must "
767+
"describe the weighted Wald-IV dose gap semantics for "
768+
"mass-point fits."
769+
)
770+
733771
def test_had_results_dataclass_docstrings_match_weighted_mass_point_contract(self):
734772
# PR #402 R3 fixed the llms-full.txt field descriptions to
735773
# acknowledge that weighted mass-point fits populate

0 commit comments

Comments
 (0)