Skip to content

Commit dd06b3b

Browse files
igerberclaude
andcommitted
Fix CI review R6: surface target metadata in standalone HonestDiD summary/export
- HonestDiDResults.summary() now renders target_label, pre/post_periods_used - HonestDiDResults.to_dict() includes target_label, pre/post_periods_used - to_dataframe() inherits from to_dict() automatically - Add test_dcdh_standalone_surfaces_target_metadata verifying all three surfaces include target metadata for custom l_vec Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 33e9c67 commit dd06b3b

2 files changed

Lines changed: 27 additions & 0 deletions

File tree

diff_diff/honest_did.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,7 @@ def summary(self) -> str:
276276
"=" * 70,
277277
"",
278278
f"{'Method:':<30} {method_display}",
279+
f"{'Target:':<30} {self.target_label}",
279280
f"{'Restriction parameter (M):':<30} {self.M:.4f}",
280281
f"{'CI method:':<30} {self.ci_method}",
281282
"",
@@ -296,6 +297,13 @@ def summary(self) -> str:
296297
]
297298

298299
# Interpretation
300+
if self.pre_periods_used is not None:
301+
lines.append(f"{'Pre horizons used:':<30} {self.pre_periods_used}")
302+
if self.post_periods_used is not None:
303+
lines.append(f"{'Post horizons used:':<30} {self.post_periods_used}")
304+
if self.pre_periods_used is not None or self.post_periods_used is not None:
305+
lines.append("")
306+
299307
lines.extend(
300308
[
301309
"-" * 70,
@@ -343,6 +351,9 @@ def to_dict(self) -> Dict[str, Any]:
343351
"ci_ub": self.ci_ub,
344352
"M": self.M,
345353
"method": self.method,
354+
"target_label": self.target_label,
355+
"pre_periods_used": self.pre_periods_used,
356+
"post_periods_used": self.post_periods_used,
346357
"original_estimate": self.original_estimate,
347358
"original_se": self.original_se,
348359
"alpha": self.alpha,

tests/test_honest_did.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1430,6 +1430,22 @@ def test_dcdh_empty_consecutive_block_raises(self):
14301430
with pytest.raises(ValueError, match="No placebo horizons with finite SEs"):
14311431
compute_honest_did(results)
14321432

1433+
def test_dcdh_standalone_surfaces_target_metadata(self):
1434+
"""Standalone HonestDiDResults summary/to_dict include target metadata."""
1435+
results = self._fit_dcdh()
1436+
bounds = compute_honest_did(results, l_vec=np.array([1.0, 0.0]))
1437+
# summary() includes target and period metadata
1438+
text = bounds.summary()
1439+
assert "on-impact" in text.lower()
1440+
assert "Post horizons used:" in text
1441+
assert "Pre horizons used:" in text
1442+
# to_dict() includes the fields
1443+
d = bounds.to_dict()
1444+
assert "target_label" in d
1445+
assert "pre_periods_used" in d
1446+
assert "post_periods_used" in d
1447+
assert d["post_periods_used"] == [1, 2]
1448+
14331449
def test_dcdh_missing_boundary_minus1_raises(self):
14341450
"""ValueError when horizon -1 has NaN SE (boundary required)."""
14351451
import warnings

0 commit comments

Comments
 (0)