Skip to content

Cross-link Matplotlib types in API docstring Returns blocks (#901)#903

Draft
drbenvincent wants to merge 1 commit into
mainfrom
901-napoleon-type-cross-refs
Draft

Cross-link Matplotlib types in API docstring Returns blocks (#901)#903
drbenvincent wants to merge 1 commit into
mainfrom
901-napoleon-type-cross-refs

Conversation

@drbenvincent
Copy link
Copy Markdown
Collaborator

Closes #901.

Summary

  • Enable napoleon_preprocess_types and define a napoleon_type_aliases map covering matplotlib (Figure, Axes), numpy (ndarray), pandas (DataFrame, Series, Index, Timestamp), xarray (DataArray, Dataset), arviz (InferenceData), pymc (Model), and pytensor (TensorVariable, RandomVariable). Both fully-qualified and short / np./pd./az./pm.-prefixed forms are aliased so existing docstrings work as-written.
  • Delete the dead numpydoc_xref_* block from docs/source/conf.py. Those keys belong to the numpydoc Sphinx extension, which is not in the extensions list — only sphinx.ext.napoleon is loaded — so the entire block was a silent no-op and was actively misleading.
  • Replace the misleading "numpydoc and autodoc typehints config" header with explicit Napoleon and sphinx-autodoc-typehints section markers so future contributors can see at a glance which extension owns which config keys.

Verification

  • sphinx-build -b html -n docs/source docs/_build warning count drops from 1047 -> 957 (-90) on this branch.
  • The headline example from the issue (InterruptedTimeSeries.plot) now renders the Returns block's fig entry as a clickable link to upstream matplotlib.figure.Figure (confirmed against the rendered HTML).
  • The Return type line emitted by sphinx-autodoc-typehints continues to render correctly — no regressions in that path.
  • prek run (on the changed file) passes.

Trade-off and follow-ups (deferred to land after #902)

Enabling Napoleon's type preprocessor reduces total warnings substantially, but introduces ~40 new ones in two specific shapes that this PR intentionally does not fix:

  1. Compound generics that Napoleon's preprocessor parses badly. Strings like tuple[plt.Figure, list[plt.Axes]], dict[str, Any], tuple[pd.Series, pd.Series], and list[matplotlib.axes.Axes] get split on the inner comma, producing broken :class: lookups. Affected primarily in causalpy/experiments/inverse_propensity_weighting.py, causalpy/experiments/panel_regression.py, and the Returns blocks of every experiment's plot() method.
  2. Project-internal names not in any intersphinx inventory. EffectSummary, BaseExperiment, CheckResult, PipelineContext appear as bare class names in docstrings; Napoleon now tries to cross-reference them and (correctly) reports them as unresolved.

These should be cleaned up in a follow-up PR sequenced after #902 lands, because:

Concretely, the follow-up PR should:

  • Rewrite compound generic type strings to forms Napoleon parses cleanly (tuple of (Figure, list of Axes), etc.) or replace them with explicit :class: role markup at the call sites where the rewrite would hurt readability.
  • Add aliases for project-internal types (EffectSummary, BaseExperiment, CheckResult, PipelineContext) so they cross-reference back into the local API docs.
  • Re-run the warning diff and confirm net warnings continue to decrease.

I'll open a follow-up issue capturing the above once this PR is in.

Independence from #902

This PR is config-only (docs/source/conf.py); #902 is pyproject.toml + docstrings. Zero file overlap, no merge order constraint either direction. They are net-additive: #902's docstring normalization makes #901's preprocessor more useful; #901's preprocessor makes #902's normalized types render as cross-references.

Made with Cursor

Enable `napoleon_preprocess_types` and define `napoleon_type_aliases` so that
type strings in NumPy-style `Parameters` and `Returns` blocks (e.g.
`matplotlib.figure.Figure`, `xarray.DataArray`, `arviz.InferenceData`) become
clickable cross-references resolved via intersphinx, instead of rendering as
plain text.

Also remove the dead `numpydoc_xref_*` configuration block, which had been
silently ignored because the `numpydoc` Sphinx extension is not loaded — only
`sphinx.ext.napoleon` parses docstrings here. Misleading comment header is
replaced with explicit "Napoleon" / "sphinx-autodoc-typehints" section
markers so future contributors can tell which extension owns which keys.

Net effect on `make html`: 1047 -> 957 warnings (-90). The headline example
from the issue (`InterruptedTimeSeries.plot` Returns block) now links
`matplotlib.figure.Figure` to the upstream Matplotlib documentation.

Co-authored-by: Cursor <cursoragent@cursor.com>
@github-actions github-actions Bot added the documentation Improvements or additions to documentation label May 1, 2026
@drbenvincent drbenvincent marked this pull request as draft May 1, 2026 20:36
@codecov
Copy link
Copy Markdown

codecov Bot commented May 1, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 94.73%. Comparing base (48144ba) to head (d18a812).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #903      +/-   ##
==========================================
- Coverage   94.74%   94.73%   -0.02%     
==========================================
  Files          84       84              
  Lines       13131    13131              
  Branches      793      793              
==========================================
- Hits        12441    12439       -2     
- Misses        487      488       +1     
- Partials      203      204       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Cross-link Matplotlib types in API docstring Returns blocks

1 participant