Skip to content

Add matplotlib import guards to tutorials 11 and 12#161

Merged
igerber merged 1 commit intomainfrom
fix-two-stage-tutorial
Feb 16, 2026
Merged

Add matplotlib import guards to tutorials 11 and 12#161
igerber merged 1 commit intomainfrom
fix-two-stage-tutorial

Conversation

@igerber
Copy link
Copy Markdown
Owner

@igerber igerber commented Feb 16, 2026

Summary

  • Add try/except ImportError matplotlib guard to cell 1 of tutorials 11 (Imputation DiD) and 12 (Two-Stage DiD)
  • Wrap plot_event_study() calls in cell 5 of both tutorials with if HAS_MATPLOTLIB: guard
  • Matches the pattern used by all other tutorials (02, 03, 05, etc.)

Methodology references (required if estimator / math changes)

  • N/A - no methodology changes

Validation

  • Tests added/updated: No test changes (tutorial-only fix)
  • Backtest / simulation / notebook evidence: Both notebooks validated via jupyter nbconvert --execute — all cells pass

Security / privacy

  • Confirm no secrets/PII in this PR: Yes

Generated with Claude Code

Tutorials 11 (Imputation DiD) and 12 (Two-Stage DiD) called
plot_event_study() without the try/except ImportError matplotlib
guard pattern used by all other tutorials. Added HAS_MATPLOTLIB
guard to cell 1 imports and wrapped plot calls in cell 5.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@github-actions
Copy link
Copy Markdown

Overall assessment: ✅ Looks good

Executive Summary

  • Added optional matplotlib import/style and plot guards in tutorials 11 and 12, making visualization cells skippable when matplotlib isn’t installed. docs/tutorials/11_imputation_did.ipynb:L22-L93, docs/tutorials/12_two_stage_did.ipynb:L22-L95
  • No estimator/math/inference changes; tutorial methodology statements for ImputationDiD and TwoStageDiD remain consistent with the Methodology Registry and estimator docstrings. docs/tutorials/11_imputation_did.ipynb:L6-L14, docs/tutorials/12_two_stage_did.ipynb:L141-L147, docs/methodology/REGISTRY.md:L464-L638, diff_diff/imputation.py:L447-L462, diff_diff/two_stage.py:L407-L420
  • Minor robustness suggestion for matplotlib style handling (see Code Quality).

Methodology

  • P3 (Info) — Impact: None; Concrete fix: None (tutorial statements remain aligned with the Methodology Registry and estimator docstrings). docs/tutorials/11_imputation_did.ipynb:L6-L14, docs/tutorials/12_two_stage_did.ipynb:L141-L147, docs/methodology/REGISTRY.md:L464-L638, diff_diff/imputation.py:L447-L462, diff_diff/two_stage.py:L407-L420

Code Quality

  • P3 — Impact: If matplotlib is installed but the seaborn-v0_8-whitegrid style is unavailable (older matplotlib), the tutorial will error despite the optional-plot guard. Concrete fix: wrap plt.style.use(...) in a broader try/except (e.g., catch OSError) and fall back to default style while keeping HAS_MATPLOTLIB=True. docs/tutorials/11_imputation_did.ipynb:L32-L39, docs/tutorials/12_two_stage_did.ipynb:L32-L39

Performance

  • P3 (Info) — Impact: None; Concrete fix: None (docs-only change).

Maintainability

  • P3 (Info) — Impact: None; Concrete fix: None (docs-only change).

Tech Debt

  • P3 (Info) — Impact: None; Concrete fix: None.

Security

  • P3 (Info) — Impact: None; Concrete fix: None (no new I/O or secrets).

Documentation/Tests

  • P3 (Info) — Impact: None; Concrete fix: None (tutorial-only update; no tests expected).

@igerber igerber merged commit bee7753 into main Feb 16, 2026
1 check passed
@igerber igerber deleted the fix-two-stage-tutorial branch February 16, 2026 23:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant