Skip to content

docs: consolidate pydantic Field descriptions with numpydoc Parameters (#1700)#2572

Open
anevolbap wants to merge 10 commits into
pymc-labs:mainfrom
anevolbap:fix/1700-consolidate-pydantic-numpydoc
Open

docs: consolidate pydantic Field descriptions with numpydoc Parameters (#1700)#2572
anevolbap wants to merge 10 commits into
pymc-labs:mainfrom
anevolbap:fix/1700-consolidate-pydantic-numpydoc

Conversation

@anevolbap
Copy link
Copy Markdown
Contributor

@anevolbap anevolbap commented May 14, 2026

Closes #1700.

Makes Field(description=...) the single source of truth for field documentation on the pydantic models that previously duplicated descriptions in a numpydoc Parameters block. A small autodoc-process-docstring callback in conf.py emits :param: / :type: directives from model_fields, so descriptions render in the published docs without an extra extension.

Touches 5 classes:

  • HSGPKwargs in pymc_marketing/hsgp_kwargs.py
  • VariableScaling, DataDerivedScaling, FixedScaling, Scaling in pymc_marketing/mmm/scaling.py

Field descriptions are expanded where the docstring carried detail the Field text didn't (cov_func, dims, FixedScaling.value). The other pydantic models in the repo are out of scope: they either have no Parameters block to consolidate or have hand-written docstrings the injector would clash with.

RTD preview: https://pymc-marketing--2572.org.readthedocs.build/en/2572/api/generated/pymc_marketing.hsgp_kwargs.HSGPKwargs.html

anevolbap added 3 commits May 14, 2026 09:39
Wire sphinxcontrib.autodoc_pydantic in conf.py with conservative defaults
(hide JSON schema, validator, and Config summaries; show field defaults
and constraints). With descriptions now sourced from Field(description=...)
on pydantic models, drop the duplicated numpydoc Parameters block on
HSGPKwargs. Refs pymc-labs#1700.
Drop the numpydoc Parameters blocks on VariableScaling, DataDerivedScaling,
FixedScaling, and Scaling. Field(description=...) is now the single source
and is rendered by autodoc-pydantic. Expand the value description on
FixedScaling and the dims description on VariableScaling to retain the
detail that was only in the docstring. Refs pymc-labs#1700.
@github-actions github-actions Bot added docs Improvements or additions to documentation MMM labels May 14, 2026
@codecov
Copy link
Copy Markdown

codecov Bot commented May 14, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.90%. Comparing base (fba000f) to head (ee74c4f).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #2572   +/-   ##
=======================================
  Coverage   93.90%   93.90%           
=======================================
  Files          92       92           
  Lines       14078    14078           
=======================================
  Hits        13220    13220           
  Misses        858      858           

☔ 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.

anevolbap and others added 2 commits May 14, 2026 17:09
…description

Restore the **emphasis** and × character that were in the original
numpydoc text for FixedScaling.value. Also move autodoc-pydantic next
to numpydoc in pyproject.toml docs extras since they are companion
rendering tools.
@anevolbap anevolbap marked this pull request as ready for review May 14, 2026 21:19
@anevolbap anevolbap changed the title WIP: docs: consolidate pydantic Field descriptions with numpydoc Parameters (#1700) docs: consolidate pydantic Field descriptions with numpydoc Parameters (#1700) May 14, 2026
The autodoc-pydantic extension did not reliably render Field
descriptions through the autosummary template on ReadTheDocs. Replace
it with a small autodoc-process-docstring callback that emits :param:
and :type: directives for the 5 pydantic classes this PR touches,
sourced from Field(description=...). Drops the autodoc-pydantic dep.
@anevolbap anevolbap marked this pull request as draft May 14, 2026 23:35
Comment thread docs/source/conf.py Outdated
return str(annotation).replace("typing.", "")


_PYDANTIC_PARAMETERS_INJECT_TARGETS = frozenset(
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will we need this?


Parameters
----------
m : int
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some of the rendering here:
https://pymc-marketing--2572.org.readthedocs.build/en/2572/api/generated/pymc_marketing.hsgp_kwargs.HSGPKwargs.html
is not amazing (missing periods / no line breaks, etc)

anevolbap added 3 commits May 15, 2026 06:00
Drop the bespoke autodoc-process-docstring callback in favor of
sphinxcontrib.autodoc_pydantic, the canonical Sphinx extension for this.
Sphinx 9.x's autosummary picks templates via hard-coded heuristics that
do not respect autodoc-pydantic's documenter priority, so generated
stubs use autoclass; a small source-read hook swaps autoclass for
autopydantic_model for any BaseModel subclass and pulls inherited
fields with :inherited-members: BaseModel. Restructure HSGPKwargs.L so
the description lives on the outer Field (instead of nested inside
Annotated, where autodoc-pydantic cannot read it), and end field
descriptions with periods.
Unescaped asterisks in two Field descriptions were interpreted as
inline-emphasis start markers; the warning only surfaces once
autopydantic_model documents these fields inline (autosummary stubs
swallow it). Wrap in double backticks to typeset as code.
… models

The autosummary class template was listing pydantic v1 legacy methods
(construct, copy, dict, from_orm, json, parse_*, schema_*, validate,
update_forward_refs, model_parametrized_name) in the Methods table and
duplicating user fields plus pydantic v2 internals (model_config,
model_fields, ...) in the Attributes table. With autopydantic_model now
documenting fields inline, drop the Attributes block for pydantic
classes and exclude the v1 aliases from Methods.
@anevolbap
Copy link
Copy Markdown
Contributor Author

anevolbap commented May 16, 2026

Drafted a smaller alternative as #2577 (option A from the issue: drops Field(description=...) instead of the numpydoc Parameters block.

@anevolbap anevolbap marked this pull request as ready for review May 17, 2026 12:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs Improvements or additions to documentation MMM

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Pydantic description, numpy docstring consolidation

2 participants