Skip to content

Enable numpydoc docstring validation for astropy.uncertainty and fix the issues - #20447

Open
ShinoKana wants to merge 3 commits into
astropy:mainfrom
ShinoKana:numpydoc-uncertainty
Open

ShinoKana wants to merge 3 commits into
astropy:mainfrom
ShinoKana:numpydoc-uncertainty

Conversation

@ShinoKana

@ShinoKana ShinoKana commented Sep 21, 2026 •

Copy link
Copy Markdown

Description

This enables the numpydoc pre-commit check for astropy.uncertainty (one subpackage of #20353) and fixes the issues it reports.

Most of them come from docstrings that describe the parameters in prose rather than in a Parameters section, so numpydoc cannot match them against the signature:

  • Distribution.pdf_mean / pdf_std / pdf_var said "Arguments are as for numpy.mean"; these now have proper Parameters sections.
  • Distribution.pdf_percentiles / pdf_histogram and the three distributions.py factory functions said "Additional keywords are passed into ..." as a trailing sentence; these are now **kwargs entries.
  • broadcast_arrays and concatenate in function_helpers.py had no Parameters section at all.

The rest are trailing blank lines at the end of a docstring (GL03), missing descriptions for ArrayDistribution.view and get_n_samples, and a few things in the private _result_as_distribution (missing space before the colon, no description for the return value).

Two descriptions were wrong rather than missing, so I corrected them while I was there:

  • broadcast_arrays: subok does not control whether subclasses of Distribution are allowed (NdarrayDistribution is one either way). What it controls is whether ndarray subclasses such as Quantity are preserved.
  • concatenate: arrays was documented as a sequence of array-like, but entries without a shape are passed straight through to numpy.concatenate, so a list or a scalar raises. Also pdf_percentiles referred to a fracs parameter that does not exist and declared the result dimensionless, while it actually keeps the unit of the samples.

One exclusion was needed. Distribution documents samples in the class docstring but takes it in __new__, and the pre-commit hook only reads signatures from __init__, so it reports samples as an unknown parameter. I have added it to [tool.numpydoc_validation] exclude with a comment, but happy to solve it differently if you would rather not carry an exclusion for this.

No behaviour changes. pytest --pyargs astropy.uncertainty passes (148 passed, 3 skipped), and numpydoc lint is clean with both numpydoc 1.10.0 (the version pinned in .pre-commit-config.yaml) and 1.11.0.

AI Disclosure

If AI tools were used to develop this pull request, describe the tools including specific model and version, how they were used, and what content is AI generated. Otherwise enter "N/A".

The docstring edits were drafted with Claude Opus 5 via Claude Code. I have gone over the full diff myself, and verified locally that python -m numpydoc.hooks.validate_docstrings astropy/uncertainty/*.py reports nothing and that the subpackage test suite still passes.

  • I certify that I am human and that I take full responsibility for this pull request including all interactions with reviewers.

Merge method

  • By checking this box, the PR author has requested that maintainers do NOT use the "Squash and Merge" button. Maintainers should respect this when possible; however, the final decision is at the discretion of the maintainer that merges the PR.

@github-actions

Copy link
Copy Markdown
Contributor

Thank you for your contribution to Astropy! 🌌 This checklist is meant to remind the package maintainers who will review this pull request of some common things to look for.

  • Do the proposed changes actually accomplish desired goals?
  • Do the proposed changes follow the Astropy coding guidelines?
  • Are tests added/updated as required? If so, do they follow the Astropy testing guidelines?
  • Are docs added/updated as required? If so, do they follow the Astropy documentation guidelines?
  • Is rebase and/or squash necessary? If so, please provide the author with appropriate instructions. Also see instructions for rebase and squash.
  • Did the CI pass? If no, are the failures related? If you need to run daily and weekly cron jobs as part of the PR, please apply the "Extra CI" label. Codestyle issues can be fixed by the bot.
  • Is a change log needed? If yes, did the change log check pass? If no, add the "no-changelog-entry-needed" label. If this is a manual backport, use the "skip-changelog-checks" label unless special changelog handling is necessary.
  • Is this a big PR that makes a "What's new?" entry worthwhile and if so, is (1) a "what's new" entry included in this PR and (2) the "whatsnew-needed" label applied?
  • At the time of adding the milestone, if the milestone set requires a backport to release branch(es), apply the appropriate "backport-X.Y.x" label(s) before merge.

out : array, optional
Alternative output array in which to place the result. It must
have the same shape and buffer length as the expected output,
but the type (of the output) will be cast if necessary.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Just a note to other reviewers that I think this is fine since we list the arguments explicitly in the signature. If we had *args, **kwargs and passed it on it would be more acceptable to just say we pass it on IMHO

@pllim

pllim commented Sep 21, 2026

Copy link
Copy Markdown
Member

This does conflicts a little with #20438 . cc @taldcroft

@pllim

pllim commented Sep 21, 2026

Copy link
Copy Markdown
Member

A rebase is also necessary to pick up new changes to pyproject.toml. FYI.

The PR09 numpydoc check was enabled on main after this branch was opened;
it flags four descriptions in astropy.uncertainty.distributions.

This branch has not been deployed

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants