Skip to content

fix(visualization): plot_event_study accepts WooldridgeDiDResults; pin the tutorial event-study idiom - #905

Merged
igerber merged 4 commits into
mainfrom
fix/plot-event-study-wooldridge
Nov 25, 2026
Merged

igerber merged 4 commits into
mainfrom
fix/plot-event-study-wooldridge

Conversation

@igerber

@igerber igerber commented Nov 25, 2026

Copy link
Copy Markdown
Owner

Summary

  • plot_event_study(WooldridgeDiDResults) raised KeyError: 'effect' (the Wooldridge event-study dict is keyed att, and aggregate("event_study") returns the results object itself rather than a container). The result is now converted to the unified EventStudyResults container at the top of plot_event_study, so it takes the existing container route end to end: stored intervals are drawn as-is, the stored-alpha mismatch warning applies, and a fit on which aggregate("event_study") has not been called raises the surface builder's ValueError naming that call.
  • On every container input, a row whose stored pointwise interval is NaN now stays without an interval under an explicit reference_period=. That path discards the stored intervals and recomputes from the SE, which would have redrawn inference a producer had deliberately disabled (WooldridgeDiD weights="cohort_share" keeps a finite conditional-on-shares SE while t/p/CI fail closed to NaN). The point estimates still plot, normalized. Applies before backend dispatch, so matplotlib and plotly agree.
  • New contract test: the one event-study idiom the tutorials will teach (es = results.aggregate("event_study") where the class has aggregate, else the result; plot_event_study(es); table from the container or to_dataframe(level="event_study")) is pinned on all thirteen event-study producers. This is the first PR of the post-4.0 tutorial repair; the tutorial convention PR cites this test.
  • TODO.md: seven library gaps found while reviewing the tutorials against 4.0 (each re-verified by execution), and the existing SunAbraham NaN-overall-ATT row gains a reproduction on the bundled divorce panel.

Methodology references (required if estimator / math changes)

  • Method name(s): Event-study plotting (plot_event_study); no estimator, weighting or variance formula changes.
  • Paper / source link(s): Wooldridge (2025), Section 7.5 (aggregate inference under estimated cohort shares) - the reason the cohort-share intervals are NaN and must stay undrawn. docs/methodology/REGISTRY.md, "Event Study Plotting", gains a Note for the Wooldridge route and the normalization guarantee.
  • Any intentional deviations from the source (and why): None.

Validation

  • Tests added/updated: tests/test_visualization.py - TestPlotEventStudyWooldridge (stored surface plotted exactly; parity with the container route; un-aggregated fit raises; stored-alpha warning; cohort-share draws no error bars, including under explicit reference_period= with both use_cband values on both backends; cell-weighted normalization keeps its recomputed intervals) and TestEventStudyIdiomContract (13 producers, plus a pin on which producers take which route).
  • Backtest / simulation / notebook evidence (if applicable): N/A - no notebooks change in this PR.

Security / privacy

  • Confirm no secrets/PII in this PR: Yes

Changelog

  • changelog.d/ fragment added (or N/A - no user-visible change): Yes

…n the event-study idiom on all 13 producers

Passing a WooldridgeDiDResults (what its aggregate('event_study') returns)
raised KeyError: 'effect' because its native dict is keyed 'att'. Convert it
to the unified EventStudyResults container at entry so it takes the container
route end to end: stored intervals drawn as-is, stored-alpha mismatch warning,
no error bars for the fail-closed cohort_share aggregation. An un-aggregated
fit raises the surface builder's ValueError naming the call to make.

Add a contract test for the event-study idiom the tutorials teach
(es = results.aggregate('event_study') where the class has aggregate, else the
result; plot_event_study(es)) across all thirteen event-study producers.

Log library gaps found by the 4.0 tutorial review in TODO.md.
…defined stored inference

On the container route, a row whose stored pointwise interval is NaN (for
example WooldridgeDiD weights='cohort_share': finite conditional-on-shares SE,
fail-closed t/p/CI) now gets a NaN SE before the explicit reference_period=
path recomputes intervals from the SE, so no interval is drawn for it on
either backend.
@github-actions

Copy link
Copy Markdown

Overall assessment: ✅ Looks good

No unmitigated P0 or P1 findings identified.

Executive summary

  • Wooldridge results correctly enter the unified container path, preserving stored intervals and alpha warnings.
  • Explicit reference normalization preserves undefined inference before either backend renders.
  • No estimator, weighting, identification, or variance formulas change.
  • Python syntax checks and changelog validation passed. Pytest could not run because the available environments lack pytest and scientific dependencies.

Methodology

  • P3 — Informational: documented inference policy preserved.
    Impact: Cohort-share aggregation retains conditional-on-shares SEs while suppressing inference that omits uncertainty in estimated shares. The conversion and normalization guard honor that contract (diff_diff/visualization/_event_study.py:L208-L247, L280-L302). Cross-checked against docs/methodology/REGISTRY.md:L2724-L2725, the new plotting Note at L7152-L7165, and the Wooldridge source quotations in docs/methodology/papers/wooldridge-2025-review.md:L532-L539.
    Concrete fix: None required.

Code Quality

No findings. Conversion reuses the existing container route, and normalization creates local dictionaries without changing stored results. Empty plot data retains its explicit ValueError.

Performance

No findings. Additional masking is linear in the number of event-study periods.

Maintainability

No findings. Reusing container extraction avoids duplicating Wooldridge-specific interval and coverage handling.

Tech Debt

  • P3 — Informational: limitations are tracked.
    Impact: The seven added backlog rows document existing API, documentation, convergence, and diagnostic gaps (TODO.md:L70-L76). They do not introduce regressions in this diff.
    Concrete fix: None required for this PR; retain the tracked follow-ups.

Security

No findings in the changed content.

Documentation/Tests

  • P3 — Optional mixed-row regression test.
    Impact: The added normalization tests cover entirely undefined and entirely defined inference separately (tests/test_visualization.py:L978-L1049). A future mask applied too broadly could suppress valid rows without those tests detecting it.
    Concrete fix: Add one container containing a reference row, a finite-SE row with NaN stored intervals, and a row with valid intervals. Under explicit normalization, assert that only the valid non-reference row retains an interval, with both use_cband settings.

The required changelog fragment is present and passes validation. Runtime test results remain unverified in this environment.

…indices

The WooldridgeDiD plotting example added to docs/api/visualization.rst is a
new code block near the top of the page, so the three context-dependent
snippets below it (formerly blocks 2, 3 and 9) are now blocks 3, 4 and 10.
@github-actions

Copy link
Copy Markdown

🔁 AI review rerun (requested by @igerber)

Head SHA: c6c56d0697839dac28adec56cbf288a6fc46634b


Overall assessment: ✅ Looks good

No unmitigated P0 or P1 findings identified.

Executive summary

  • Wooldridge results enter the unified container path, preserving stored intervals and alpha warnings.
  • Explicit normalization preserves undefined inference.
  • No estimator, weighting, identification, or variance formulas change.
  • The prior review’s optional mixed-row regression test remains absent.
  • Syntax and changelog checks passed. Runtime tests could not run because the available environments lack pytest and scientific dependencies.

Methodology

  • P3 — Informational: documented inference policy preserved.
    Impact: The conversion preserves Wooldridge’s stored inference; normalization suppresses intervals where stored pointwise inference is undefined (diff_diff/visualization/_event_study.py:L208-L247, L280-L302). This follows the registry’s cohort-share inference contract and new plotting Note (docs/methodology/REGISTRY.md:L2724-L2726, L7152-L7165). The repository’s Wooldridge (2025) source excerpts confirm that aggregate inference must account for estimated cohort shares (docs/methodology/papers/wooldridge-2025-review.md:L532-L538).
    Concrete fix: None required.

Code Quality

No findings. The change reuses container extraction, avoids mutating stored results, and retains the empty-data ValueError. No new inline t-statistic computation or partial inference guard was found.

Performance

No findings. Conversion and masking require linear work in the number of event-study rows.

Maintainability

No findings. Reusing the unified container route keeps interval handling and coverage warnings consistent.

Tech Debt

  • P3 — Informational: existing limitations are tracked.
    Impact: The added rows record existing API, convergence, documentation, and diagnostic limitations (TODO.md:L70-L76). They do not introduce regressions.
    Concrete fix: None required for this PR; retain the tracked follow-ups.

Security

No findings in the changed content.

Documentation/Tests

  • P3 — Optional mixed-row regression test remains outstanding from the prior review.
    Impact: Current tests cover entirely undefined and entirely defined inference separately (tests/test_visualization.py:L980-L1049). They would not detect a future mask that suppresses valid intervals only when undefined rows coexist.
    Concrete fix: Add one container containing a reference row, a finite-SE row with NaN stored intervals, and a row with valid intervals. Under explicit normalization, assert that only the valid non-reference row retains an interval, with both use_cband settings.

The required changelog fragment is present and passes validation. Changed Python files and visualization documentation snippets compile successfully. Runtime tests remain unverified because pytest, NumPy, pandas, SciPy, matplotlib, and plotly are unavailable.

@igerber
igerber merged commit fa3e34a into main Nov 25, 2026
35 checks passed
@igerber
igerber deleted the fix/plot-event-study-wooldridge branch November 25, 2026 19:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ready-for-ci Triggers CI test workflows

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant