Repository navigation
Phase 5: Plotting, public API, and runtime checks - #9
Merged
Merged
Conversation
thomaspinder
force-pushed
the
phase-4-identification
branch
2 times, most recently
from
February 22, 2026 11:25
03ac218 to
52859c9
Compare
Implements plot_irf, plot_forecast, plot_fevd, plot_historical_decomposition. Wires up __init__.py with VAR, VARData, select_lag_order re-exports and enable_runtime_checks() for beartype integration. Adds scipy dependency for SignRestriction. Final landing page showcases full pipeline with structural analysis. Complete Diataxis documentation: 3 tutorials, 4 how-tos, 3 explanations, 11 API reference pages. 64 fast + 12 slow tests. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
thomaspinder
force-pushed
the
phase-5-plotting-api
branch
from
February 22, 2026 11:39
25eb24e to
eb68d8d
Compare
This was referenced May 18, 2026
thomaspinder
added a commit
that referenced
this pull request
May 18, 2026
…72) (#73) Previously, IRFResult/FEVDResult/HistoricalDecompositionResult collapsed the named (response, shock) axes into anonymous integer columns, and HD also lost its time axis via the (T*n, n) reshape. Callers had to reverse- engineer the flatten order, and per-row HD access silently misaligned. - src/impulso/results.py: add `_wide_frame` helper; rewrite IRF/FEVD/HD `.median()` and `.hdi()` to return wide DataFrames with `MultiIndex(['response','shock'])` on columns; integer horizon index for IRF/FEVD, DatetimeIndex for HD. `.to_dataframe()` stays as a `.median()` passthrough pending the dedicated follow-up (audit #9). - src/impulso/identified.py: attach `"time"` coord on the HD DataArray so the new HD accessor can build its DatetimeIndex. - src/impulso/plotting/_irf.py: replace `med.values[:, col_idx]` integer arithmetic with label-based `med[(resp, shock)]` lookups; pull shock names from the DataArray's `shock` coord. - tests/test_results.py: 9 new tests across IRF/FEVD/HD locking the new contract — MultiIndex column labels round-trip the underlying DataArray values, HD index is a DatetimeIndex matching `data.index[n_lags:]`, HDIResult.lower / .upper mirror shape and labels. Closes audit findings #1 and #10 (reports/audit-2026-05-18.md). Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Completes the library with a plotting package, public API re-exports, and optional runtime type checking via beartype.
Plotting Package (
src/litterman/plotting/)Four plot functions, each accepting a result object and returning a
matplotlib.Figure:plot_irf(result, variables=None, figsize)— Grid of IRF subplots (shock x response) with posterior median lines and HDI credible bands. Zero reference line included.plot_forecast(result, figsize)— Per-variable fan charts with posterior median and HDI fillplot_fevd(result, figsize)— Stacked area chart of variance decomposition shares across horizonsplot_historical_decomposition(result, figsize)— Stacked bar chart of shock contributions over timeAll use
TYPE_CHECKINGguards for lazy imports to avoid circular dependencies. Re-exported fromlitterman.plotting.__init__.Public API (
src/litterman/__init__.py)Clean top-level exports:
Runtime Type Checking
enable_runtime_checks()wraps all public classes acrossdata,spec,fitted, andidentifiedmodules withbeartypedecorators. Usescontextlib.suppress(BeartypeDecorHintPep484585Exception)to skip types beartype cannot handle (e.g., complex Pydantic generics).Dependencies
beartype>=0.18topyproject.tomldependenciesTests
test_plotting.py(4 tests) — Verifies all four plot functions are importable and callable (usesmatplotlib.use("Agg")for headless testing)test_public_api.py(4 tests) — VerifiesVAR,VARData,select_lag_order,enable_runtime_checksare importable from top-levellittermanDocumentation
reference/plotting.md)Files Changed (13 files, +296 / -6)
__init__.py(+35),plotting/__init__.py(+7)plotting/_irf.py(+53),plotting/_forecast.py(+42),plotting/_fevd.py(+34),plotting/_historical_decomposition.py(+42)test_plotting.py(+27),test_public_api.py(+23)pyproject.toml(+1 dep),uv.lockreference/plotting.md, updatedindex.md,mkdocs.ymlTest plan
uv run pytest tests/test_plotting.py tests/test_public_api.py -v— all import/API tests passuv run pytest tests/ -m "not slow" -v— full fast suite (64 tests)uv run pytest tests/ -v— full suite including slow tests (76 tests)uv run ruff check . && uv run ruff format --check .python -c "from litterman import VAR, VARData, select_lag_order, enable_runtime_checks"— imports work🤖 Generated with Claude Code