Fix tutorial notebook validation errors and add pre_periods parameter#74
Fix tutorial notebook validation errors and add pre_periods parameter#74
Conversation
Tutorial notebook fixes: - 02_staggered_did: Fix CallawaySantAnna API usage (first_treat param, aggregate attributes instead of method) - 03_synthetic_did: Change n_bootstrap=0 to variance_method="placebo" - 04_parallel_trends: Fix placebo test API (parameter names, required args) - 07_pretrends_power: Add pre_periods parameter for event study workflow - 10_trop: Reduce computational load for faster validation Code fixes: - staggered.py: Standardize first_treat column name internally to avoid hardcoded column reference bug - pretrends.py: Add pre_periods parameter to fit(), power_at(), power_curve(), and sensitivity_to_honest_did() methods to support event studies where all periods are estimated as post_periods - pretrends.py: Add power_at() method to PreTrendsPowerResults class - pretrends.py: Update convenience functions with pre_periods parameter Other: - Move TROP paper to papers/ directory - Add .claude/settings.local.json to .gitignore - Clear all notebook outputs Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Code Review: PR #74Executive SummaryThis PR makes two types of changes: (1) tutorial notebook fixes to align with current API, and (2) code fixes/enhancements to Part 1: Methodology Review1.1
|
| Category | Rating | Notes |
|---|---|---|
| Performance | ✅ Good | No concerns - O(n) column copy, reuses stored vcov |
| Memory | ✅ Good | No new allocations |
| Maintainability | Test debt, weight duplication |
Recommendations
Must Fix Before Merge
- Add tests for new functionality (see above)
- Fix weight computation inconsistency between
PreTrendsPowerResults.power_at()andPreTrendsPower._get_violation_weights()
Should Fix
- Consistent parameter naming: keep
target_poweror rename both topower
Nice to Have
- Store violation weights in results object
- Add warning when
power_at()called withviolation_type='custom'
Summary
| Category | Rating |
|---|---|
| Methodology | ✅ Correct |
| Code Quality | |
| Performance | ✅ Good |
| Overall | Needs Revision |
The methodology is sound but please add tests and fix the weight inconsistency before merging.
Fixes: - Fix weight computation in PreTrendsPowerResults.power_at() to match _get_violation_weights() logic (linear weights should be [n-1, n-2, ..., 0]) - Fix compute_mdv() parameter name from 'power' back to 'target_power' for consistency with compute_pretrends_power() - Update notebook cell-28 to use target_power instead of power Tests added: - TestPreTrendsPowerResultsPowerAt: 6 tests for power_at() method - TestPrePeriodsParameter: 6 tests for pre_periods parameter - TestCallawaySantAnnaNonStandardColumnNames: 10 tests for non-standard column names in CallawaySantAnna Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Re-review: Commit 336e246 ✅The follow-up commit successfully addresses all critical and medium-priority issues from my initial review. Issues Resolved
Test ResultsAll 21 new tests pass: Code Quality AssessmentTests are thorough and well-designed:
Minor NoteThere are some Final Assessment
Ready to merge. Nice work addressing the feedback! |
Add TODO item for RuntimeWarnings that occur during influence function aggregation in staggered.py. These warnings (divide by zero, overflow, invalid value in matmul) occur with small sample sizes or edge cases but don't affect result correctness. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Tutorial notebook fixes:
Code fixes:
Other: