Skip to content

docs(tutorials): tutorial conventions and a CI guard for them - #906

Merged
igerber merged 4 commits into
mainfrom
docs/tutorial-conventions
Nov 25, 2026
Merged

igerber merged 4 commits into
mainfrom
docs/tutorial-conventions

Conversation

@igerber

@igerber igerber commented Nov 25, 2026 •

Copy link
Copy Markdown
Owner

Summary

Second PR of the post-4.0 tutorial repair (the first is #905). It adds the convention and the guard; it edits no notebook. Each notebook is then repaired, re-executed and removed from the allowlist in one of six follow-up track PRs.

  • CONTRIBUTING.md - "Tutorial conventions". What every notebook states and how: an estimand-and-assumptions block before the first fit; a truth check on simulated data with the truth-determining generator arguments passed explicitly; unit-clustered inference and which p-values are count-based; pre-trend tests are never pass/fail; never-treated vs not-yet-treated as different assumptions; one event-study idiom; no unqualified warning suppression; a standard closing; reader voice (no migration narration, ledger ids, PR numbers or file:line references); committed outputs; a drift test per notebook. Also the recipe for re-executing a notebook.
  • tests/test_tutorial_conventions.py. Enforces the mechanical rules over every docs/tutorials/*.ipynb by parsing the notebook JSON (nothing is executed): execution counts 1..n, no committed error output, no removed 4.0 names (overall_att, MultiPeriodDiD, StaggeredTripleDifference) or removed classes/aliases used as code identifiers, no internal jargon, no unqualified filterwarnings("ignore") / simplefilter("ignore") (call arguments inspected through the AST), no em dashes in sources, no HAS_MATPLOTLIB guard, exactly one drift test per notebook.
  • PENDING. 34_chained_did (Add experimental native ChainedDiD for incomplete panels #887) and 34_did_ovb (Add DiD OVB sensitivity analysis and reproduction benchmarks #835) are exempt until conformed, so whichever lands first does not break main. Both share the number 34 with 34_design_diagnosis, which is why shared-number notebooks need an explicit drift-test mapping. Conforming those two and emptying PENDING is a follow-up after the track PRs.
    • Ratchet allowlist. KNOWN_VIOLATIONS records the rules each of 29 notebooks violates today. The guard fails on any unlisted violation and also when a listed one has been fixed, so a repair PR must delete its entries; the dict is meant to end empty. Error outputs can never be allowlisted.
    • Each rule has fixtures showing it fires on a violation and stays quiet on a conforming cell.
  • CI wiring. docs-tests.yml runs the guard (its path filters already cover docs/**; the test file's own path is added). notebooks.yml now runs every tests/test_t*_drift.py instead of only the two MMM ones, and triggers on drift-test changes: until now a notebook-only diff ran no lane that executes the drift tests (about 9 s on the pure-Python backend, slow-marked tests excluded). Both wirings are self-pinned in the new test file.
  • docs/tutorials/README.md is reduced to a pointer to index.rst and the conventions (the old hand-maintained list omitted eleven notebooks, 05-14 and 28, and stated Python 3.8+).

Convention 7 cites tests/test_visualization.py::TestEventStudyIdiomContract, which is added by #905.

Methodology references (required if estimator / math changes)

  • Method name(s): N/A - no methodology changes. The p-value wording in the convention restates docs/methodology/REGISTRY.md (permutation test (c+1)/(B+1); SyntheticDiD placebo max(c/B, 1/(B+1))).
  • Paper / source link(s): N/A
  • Any intentional deviations from the source (and why): None

Validation

  • Tests added/updated: tests/test_tutorial_conventions.py (new: one parametrized guard test per notebook, configuration consistency, rule fixtures, workflow pins).
  • Backtest / simulation / notebook evidence (if applicable): N/A - no notebooks change. The allowlist was generated by running the rules over the 35 notebooks on main; six are already clean (27-31, 34).

Security / privacy

  • Confirm no secrets/PII in this PR: Yes

Changelog

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

CONTRIBUTING.md gains a 'Tutorial conventions' section: what every notebook
states and how (estimand and assumptions, truth check on simulated data,
clustered inference and which p-values are count-based, one event-study
idiom, warnings, committed outputs, a drift test per notebook, reader voice),
plus the recipe for re-executing a notebook.

tests/test_tutorial_conventions.py enforces the mechanical rules over every
notebook by parsing the notebook JSON: execution counts, no committed error
output (never allowlistable), no removed 4.0 names or aliases, no internal
jargon, no unqualified warning suppression, no em dashes, no HAS_MATPLOTLIB
guard, a drift test per notebook. A ratchet allowlist records today's
violations; repair PRs must shrink it. It runs in docs-tests.yml, and the
workflow wiring is self-pinned.

notebooks.yml now runs every tutorial drift test, so a notebook-only diff
cannot leave its pinned numbers unchecked.

docs/tutorials/README.md is reduced to a pointer to the tutorial index and
the conventions.
@github-actions

Copy link
Copy Markdown

Overall assessment: ✅ Looks good

No unmitigated P0 or P1 findings. Two P2 issues remain.

Executive summary

  • No estimator, weighting, variance, or identification behavior changes.
  • The p-value guidance agrees with the Methodology Registry.
  • Aliased warning filters can bypass the new guard.
  • The diff unexpectedly deletes the Wang methodology review and its changelog fragment.
  • A standard-library harness passed all 92 assertion cases, covering 35 notebooks. Pytest and numerical dependencies were unavailable, so the drift suite was not run.

Methodology

No methodology defects found. The permutation-test correction and SyntheticDiD placebo floor match the PlaceboTests and SyntheticDiD Registry sections. ChangesInChanges uses analytical inference from its bootstrap SE, consistent with the new guidance.

Code Quality

P2 — Recognize aliased warning-filter imports

Location: tests/test_tutorial_conventions.py:L322-L325

Impact: from warnings import simplefilter as sf; sf("ignore") passes the guard while suppressing every warning. The same bypass works for aliased filterwarnings. This leaves convergence and assumption warnings unprotected by the intended convention.

Concrete fix: Resolve imports of warning-filter functions to their canonical names, including aliases imported in earlier cells. Add fixtures for both aliased functions, with blanket filters rejected and qualified filters accepted.

Performance

No findings. The new guard parses notebook JSON without executing notebooks.

Maintainability

No findings.

Tech Debt

No additional findings. The existing violations and pending-notebook exemptions are explicitly documented as transitional.

Security

No findings.

Documentation/Tests

P2 — Restore the unrelated Wang source review

Locations: docs/methodology/papers/wang-2026-review.md:L1-L12 and changelog.d/20261125-wang-paper-review.md:L1-L11 (deleted files; base-version lines).

Impact: This removes the complete OVB methodology audit, including implementation requirements and unresolved inference questions, along with its release note. Neither deletion supports the tutorial-conventions change, and no replacement is present.

Concrete fix: Restore both files; handle any intended withdrawal separately with an explicit rationale.

…tions guard

from warnings import simplefilter as sf; sf('ignore') - or an assignment
alias, possibly created in an earlier cell - no longer bypasses the
blanket-warning-filter rule.
@github-actions

Copy link
Copy Markdown

🔁 AI review rerun (requested by @igerber)

Head SHA: 01453a5f9a844dd56cae3cbc8d961b91890cac7f


Overall assessment: ✅ Looks good

Both previous P2 findings are resolved. No unmitigated P0 or P1 findings.

Executive summary

  • Aliased warning filters are now recognized, including imports in earlier cells; qualified filters remain accepted.
  • The Wang methodology review and its changelog fragment are restored.
  • The inference guidance agrees with the Methodology Registry.
  • All 93 static test cases passed in a standard-library harness covering 35 notebooks. Pytest and numerical dependencies were unavailable, so the numerical drift suite was not run.

Methodology

No defects found. The permutation formula (c+1)/(B+1) and SyntheticDiD placebo formula max(c/B, 1/(B+1)) match their Registry entries. The analytical-inference wording matches SyntheticDiD bootstrap/jackknife and ChangesInChanges.

No estimator, variance, weighting, or identification behavior changes.

Code Quality

Previous alias finding resolved in tests/test_tutorial_conventions.py:L306-L402. Cross-cell checks reject blanket suppression through both imported aliases and assigned aliases, while accepting qualified filters. No further findings.

Performance

No findings. The conventions guard reads notebook JSON without executing notebook code.

Maintainability

No findings. Configuration checks and workflow assertions cover the allowlist and CI wiring.

Tech Debt

No findings requiring action. Existing violations and pending notebooks remain explicitly recorded as transitional exceptions.

Security

No findings in the changed code or workflow commands.

Documentation/Tests

Previous deletion finding resolved: both docs/methodology/papers/wang-2026-review.md and changelog.d/20261125-wang-paper-review.md are present and tracked.

The new changelog fragment is present, and the repository’s fragment validator passes. Static validation passed as described above; numerical drift execution remains unverified locally.

…paper does

Tutorial convention 6 said neither the never-treated nor the not-yet-treated
assumption is uniformly weaker. Callaway and Sant'Anna (2021) do not rank
them; they say the not-yet-treated version additionally restricts
pre-treatment trends across cohorts, and suggest never-treated when that
group is sizeable. The convention now says that.
@github-actions

Copy link
Copy Markdown

🔁 AI review rerun (requested by @igerber)

Head SHA: 45fa609a3672f136d154db223fdbafcd26b5bcd7


Overall assessment: ✅ Looks good

Both previous P2 findings remain resolved. No unmitigated P0 or P1 findings.

Executive summary

  • Warning-filter aliases remain covered, including aliases defined in earlier cells.
  • The Wang paper review and its changelog fragment are present and tracked.
  • The inference guidance agrees with the Methodology Registry and implementation.
  • All 93 static cases passed using a standard-library harness across 35 notebooks. The changelog validator also passed.
  • Numerical drift tests could not run locally because pytest and numerical dependencies are unavailable.

Methodology

No findings. No estimator, weighting, variance, or identification behavior changes.

The guidance in CONTRIBUTING.md:L183-L206 preserves the distinction between permutation and SyntheticDiD placebo p-values, correctly describes inference from resampled standard errors, and distinguishes Callaway–Sant’Anna’s comparison-group assumptions.

Code Quality

No findings. The previous alias-handling issue remains resolved in tests/test_tutorial_conventions.py:L306-L402; the corresponding fixtures passed.

Performance

No findings. The new guard parses notebook JSON without executing cells. The expanded workflow selects the existing drift modules and retains the default exclusion of slow tests.

Maintainability

No findings. Configuration checks cover stale allowlist entries, prohibited exceptions, and drift-test mappings. Workflow assertions pin the added CI wiring.

Tech Debt

No findings requiring action. Existing notebook violations and pending notebooks are explicitly recorded as transitional exceptions.

Security

No findings in the changed code or workflow commands.

Documentation/Tests

No findings requiring action. The new changelog fragment follows repository conventions, and both modified workflows parse successfully.

Validation covers the static guard and changelog format; numerical drift results remain unverified locally.

@igerber igerber added the ready-for-ci Triggers CI test workflows label Nov 25, 2026
@igerber
igerber merged commit b7511f1 into main Nov 25, 2026
64 of 66 checks passed
@igerber
igerber deleted the docs/tutorial-conventions branch November 25, 2026 21:23
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