Skip to content

Commit 46273b6

Browse files
igerberclaude
andcommitted
Fix CI review Round 6: joiners_leavers n_obs, stale docstrings
P1: Fix to_dataframe("joiners_leavers") overall row n_obs: use n_treated_obs when joiners/leavers are suppressed (non-binary) instead of summing zeroed joiner/leaver obs counts. P2: Add joiners_leavers and summary() assertions to test_nonbinary_lmax1_renderer_contract. P3: Update to_dataframe() docstring: event_study/normalized available at L_max >= 1 (was >= 2). Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 56b2526 commit 46273b6

2 files changed

Lines changed: 15 additions & 3 deletions

File tree

diff_diff/chaisemartin_dhaultfoeuille_results.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -788,9 +788,9 @@ def to_dataframe(self, level: str = "overall") -> pd.DataFrame:
788788
the A11-zeroed flags.
789789
- ``"event_study"``: one row per horizon (positive and
790790
negative/placebo), including a reference period at
791-
horizon 0. Available when ``L_max >= 2``.
791+
horizon 0. Available when ``L_max >= 1``.
792792
- ``"normalized"``: one row per horizon for the normalized
793-
effects ``DID^n_l``. Available when ``L_max >= 2``.
793+
effects ``DID^n_l``. Available when ``L_max >= 1``.
794794
- ``"twfe_weights"``: per-(group, time) TWFE decomposition
795795
weights table. Only available when ``twfe_diagnostic=True``
796796
was passed to ``fit()``.
@@ -847,7 +847,11 @@ def to_dataframe(self, level: str = "overall") -> pd.DataFrame:
847847
"conf_int_lower": self.overall_conf_int[0],
848848
"conf_int_upper": self.overall_conf_int[1],
849849
"n_cells": self.n_switcher_cells,
850-
"n_obs": self.n_joiner_obs + self.n_leaver_obs,
850+
"n_obs": (
851+
self.n_treated_obs
852+
if not self.joiners_available and not self.leavers_available
853+
else self.n_joiner_obs + self.n_leaver_obs
854+
),
851855
"available": True,
852856
},
853857
{

tests/test_chaisemartin_dhaultfoeuille.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2454,6 +2454,14 @@ def test_nonbinary_lmax1_renderer_contract(self):
24542454
# Joiners/leavers unavailable for non-binary
24552455
assert r.joiners_available is False
24562456
assert r.leavers_available is False
2457+
# to_dataframe("joiners_leavers"): overall row n_obs should be > 0
2458+
df_jl = r.to_dataframe("joiners_leavers")
2459+
overall_row = df_jl[df_jl["estimand"] == "DID_1"]
2460+
assert len(overall_row) == 1
2461+
assert overall_row.iloc[0]["n_obs"] > 0
2462+
# summary() should contain "DID_1" label
2463+
s = r.summary()
2464+
assert "DID_1" in s
24572465

24582466
def test_twfe_diagnostic_skipped_nonbinary(self):
24592467
"""TWFE diagnostic should be skipped (with warning) for non-binary."""

0 commit comments

Comments
 (0)