Skip to content

Commit bbe584f

Browse files
igerberclaude
andcommitted
Fix test_nan_inference for pure Python mode
Expand minimal test dataset from 4 to 6 observations (3 units × 2 periods) to avoid saturated model (n=k=4) which causes division by zero in cluster-robust VCV adjustment. The Rust backend handles this gracefully but pure Python's (n-1)/(n-k) term requires n > k. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 2026f57 commit bbe584f

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

tests/test_stacked_did.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -616,14 +616,16 @@ def test_unbalanced_panel(self):
616616

617617
def test_nan_inference(self):
618618
"""Degenerate case with NaN inference fields."""
619-
# Create minimal data where estimation might degenerate
620-
# kappa_pre=1 gives window [a-1, a+0] = 2 periods, just enough
619+
# Create small data where estimation might degenerate.
620+
# Need n > k to avoid division by zero in cluster-robust VCV:
621+
# Design matrix has 4 columns (intercept, D_sa, lambda_0, delta_0),
622+
# so we need > 4 observations (3 units × 2 periods = 6).
621623
data = pd.DataFrame(
622624
{
623-
"unit": [1, 1, 2, 2],
624-
"period": [1, 2, 1, 2],
625-
"outcome": [1.0, 2.0, 1.0, 2.0],
626-
"first_treat": [2, 2, 0, 0],
625+
"unit": [1, 1, 2, 2, 3, 3],
626+
"period": [1, 2, 1, 2, 1, 2],
627+
"outcome": [1.0, 2.0, 1.0, 2.0, 1.5, 2.5],
628+
"first_treat": [2, 2, 0, 0, 0, 0],
627629
}
628630
)
629631
est = StackedDiD(kappa_pre=1, kappa_post=0)

0 commit comments

Comments
 (0)