Skip to content

Commit 2d663d9

Browse files
igerberclaude
andcommitted
Fix test_all_same_dose bootstrap assertion on macOS
Add noise to outcomes in bootstrap regression test so residuals are non-zero across platforms. Identical outcomes produce zero residuals, giving zero-variance bootstrap distributions and SE=0 → NaN on macOS. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 6e570a7 commit 2d663d9

1 file changed

Lines changed: 16 additions & 1 deletion

File tree

tests/test_methodology_continuous_did.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,21 @@ def test_all_same_dose(self):
193193

194194
# Verify bootstrap path also produces finite ATT SE (not NaN) for
195195
# rank-deficient cells — regression test for P1 bootstrap fix.
196+
# Use noisy outcomes so residuals are non-zero, giving the bootstrap
197+
# actual variance to measure (identical outcomes → zero residuals →
198+
# zero-variance bootstrap → SE=0 → NaN by design on all platforms).
199+
rng = np.random.default_rng(123)
200+
rows_noisy = []
201+
for i in range(n_control):
202+
noise = rng.normal(0, 0.1)
203+
rows_noisy.append({"unit": i, "period": 1, "outcome": noise, "first_treat": 0, "dose": 0.0})
204+
rows_noisy.append({"unit": i, "period": 2, "outcome": noise, "first_treat": 0, "dose": 0.0})
205+
for j in range(n_treated):
206+
uid = n_control + j
207+
noise = rng.normal(0, 0.1)
208+
rows_noisy.append({"unit": uid, "period": 1, "outcome": noise, "first_treat": 2, "dose": dose_val})
209+
rows_noisy.append({"unit": uid, "period": 2, "outcome": 5.0 + noise, "first_treat": 2, "dose": dose_val})
210+
data_noisy = pd.DataFrame(rows_noisy)
196211
# ACRT SE is correctly NaN: zero dose variation → zero-variance
197212
# bootstrap distribution → degenerate SE → NaN by design.
198213
est_boot = ContinuousDiD(
@@ -201,7 +216,7 @@ def test_all_same_dose(self):
201216
)
202217
with pytest.warns(UserWarning, match="[Ii]dentical"):
203218
results_boot = est_boot.fit(
204-
data, "outcome", "unit", "period", "first_treat", "dose"
219+
data_noisy, "outcome", "unit", "period", "first_treat", "dose"
205220
)
206221
assert np.all(np.isfinite(results_boot.dose_response_att.se))
207222

0 commit comments

Comments
 (0)