Skip to content

Commit ea86541

Browse files
igerberclaude
andcommitted
Add SunAbraham survey validation + TwoStage NotImplementedError propagation
P1: SunAbraham now calls _validate_unit_constant_survey() before Rao-Wu collapse, rejecting within-unit-varying survey columns P2: TwoStageDiD re-raises NotImplementedError (e.g. lonely_psu=adjust) instead of swallowing it in the generic except Exception handler Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 6218e45 commit ea86541

2 files changed

Lines changed: 12 additions & 1 deletion

File tree

diff_diff/sun_abraham.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -502,12 +502,21 @@ def fit(
502502
raise ValueError(f"Missing columns: {missing}")
503503

504504
# Resolve survey design if provided
505-
from diff_diff.survey import _resolve_effective_cluster, _resolve_survey_for_fit
505+
from diff_diff.survey import (
506+
_resolve_effective_cluster,
507+
_resolve_survey_for_fit,
508+
_validate_unit_constant_survey,
509+
)
506510

507511
resolved_survey, survey_weights, survey_weight_type, survey_metadata = (
508512
_resolve_survey_for_fit(survey_design, data, "analytical")
509513
)
510514

515+
# Validate survey columns are constant within units (required for
516+
# unit-level collapse in Rao-Wu bootstrap)
517+
if resolved_survey is not None:
518+
_validate_unit_constant_survey(data, unit, survey_design)
519+
511520
# Bootstrap + survey supported via Rao-Wu rescaled bootstrap.
512521
# Determine Rao-Wu eligibility from the *original* survey_design
513522
# (before cluster-as-PSU injection which adds PSU to weights-only designs).

diff_diff/two_stage.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -585,6 +585,8 @@ def fit(
585585
aggregate=aggregate,
586586
resolved_survey=resolved_survey,
587587
)
588+
except NotImplementedError:
589+
raise # Don't swallow explicit rejections (e.g. lonely_psu="adjust")
588590
except Exception as e:
589591
warnings.warn(
590592
f"Bootstrap failed: {e}. Skipping bootstrap inference.",

0 commit comments

Comments
 (0)