Skip to content

Enable numpydoc docstring validation for astropy.cosmology - #20774

Merged
pllim merged 3 commits into
astropy:mainfrom
nstarman:claude/numpydoc-violations-cosmology-5af9d3
Nov 5, 2026
Merged

pllim merged 3 commits into
astropy:mainfrom
nstarman:claude/numpydoc-violations-cosmology-5af9d3

Conversation

@nstarman

@nstarman nstarman commented Nov 3, 2026

Copy link
Copy Markdown
Member

Description

Remove astropy/cosmology from the numpydoc-validation exclude list and fix the reported docstring issues: document missing parameters and return values, fix punctuation/capitalization, remove extra blank lines, and fix stale or misordered parameter docs.

Some reports are false positives of the static (AST-based) hook and are silenced inline with # numpydoc ignore=...:

  • dataclass-generated __init__ (Cosmology subclasses, Parameter, ParametersAttribute) whose parameters are documented on the class;
  • the unified I/O descriptor classes, which document __call__;
  • format, which is added by _comparison_decorator;
  • small private closures / helpers that defer to another docstring.

AI Disclosure

I ran numpydoc and fed it to an agent to fix. I reviewed.

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

…e issues

Remove astropy/cosmology from the numpydoc-validation exclude list and fix
the reported docstring issues: document missing parameters and return
values, fix punctuation/capitalization, remove extra blank lines, and fix
stale or misordered parameter docs.

Some reports are false positives of the static (AST-based) hook and are
silenced inline with ``# numpydoc ignore=...``:
- dataclass-generated ``__init__`` (Cosmology subclasses, Parameter,
  ParametersAttribute) whose parameters are documented on the class;
- the unified I/O descriptor classes, which document ``__call__``;
- ``format``, which is added by ``_comparison_decorator``;
- small private closures / helpers that defer to another docstring.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@github-actions

github-actions Bot commented Nov 3, 2026

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.

@nstarman nstarman moved this from Triage to In Progress in Cosmology, the Expansion Nov 3, 2026
@nstarman
nstarman marked this pull request as ready for review November 4, 2026 01:02
@nstarman
nstarman requested review from a team and neutrinoceros as code owners November 4, 2026 01:02
@nstarman
nstarman requested a lite review from Copilot November 4, 2026 01:02

Copilot AI left a comment

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.

Note

Copilot was unable to complete this review at the selected tier due to model policy or plan restrictions.

🟡 Changes recommended

The change still has unresolved documentation nits—including misleading/inaccurate docstrings and minor grammar—that should be corrected to avoid confusion and potential future lint failures.

2 open issues
What changed in this PR

This PR enables numpydoc docstring validation for astropy.cosmology by removing the package from the validation exclude list and bringing cosmology docstrings into compliance, with targeted inline ignore annotations for known static-check false positives.

Changes:

  • Remove astropy/cosmology from the numpydoc-validation exclude list (pyproject.toml).
  • Fix/complete numerous docstrings in astropy.cosmology (parameters/returns, punctuation/capitalization, ordering, and blank-line cleanup).
  • Add scoped # numpydoc ignore=... markers for dataclass-generated/decorated signatures and small helper closures that confuse the AST-based validator.
File Description
pyproject.toml Stops excluding astropy/cosmology from numpydoc validation.
astropy/​cosmology/​__init__.py Documents lazy __getattr__ realization access.
astropy/​cosmology/​realizations.py Documents lazy __getattr__ realization construction and return type.
astropy/​cosmology/​parameters.py Expands __getattr__ docstring for lazy parameter mapping access.
astropy/​cosmology/​_src/​core.py Adds/cleans docstrings for dataclass/signature helpers and base Cosmology class behavior; adds numpydoc ignores for dataclass signature noise.
astropy/​cosmology/​_src/​default.py Clarifies default_cosmology.validate parameter/return semantics in docstring.
astropy/​cosmology/​_src/​utils.py Docstring cleanup plus numpydoc ignore for vectorize_redshift_method wrapper; documents aszarr and docstring formatting fixes.
astropy/​cosmology/​_src/​units_equivalencies.py Docstring capitalization/punctuation fixes; adds numpydoc ignores for small closure helpers in equivalency factories.
astropy/​cosmology/​_src/​funcs/​optimize.py Adds numpydoc ignore for private scalar helper; reorders docstring sections to satisfy numpydoc expectations.
astropy/​cosmology/​_src/​funcs/​comparison.py Adds missing return docs; adds numpydoc ignore for decorator-injected signature artifacts.
astropy/​cosmology/​_src/​flrw/​base.py Docstring whitespace cleanup; adds numpydoc ignore for dataclass-generated FLRW init docs; expands validator docstrings.
astropy/​cosmology/​_src/​flrw/​lambdacdm.py Adds missing parameter/return docs for helper functions; adds numpydoc ignore for dataclass-generated init docs.
astropy/​cosmology/​_src/​flrw/​w0cdm.py Adds numpydoc ignore for dataclass-generated init docs.
astropy/​cosmology/​_src/​flrw/​w0wacdm.py Reorders references/examples to satisfy numpydoc; adds numpydoc ignore for dataclass-generated init docs.
astropy/​cosmology/​_src/​flrw/​w0wzcdm.py Reorders references/notes in method docstring; adds numpydoc ignore for dataclass-generated init docs.
astropy/​cosmology/​_src/​flrw/​wpwazpcdm.py Moves examples after references; punctuation fixes; adds numpydoc ignore for dataclass-generated init docs.
astropy/​cosmology/​_src/​traits/​baryons.py Docstring whitespace cleanup.
astropy/​cosmology/​_src/​traits/​curvature.py Docstring whitespace cleanup and minor formatting fixes.
astropy/​cosmology/​_src/​traits/​darkmatter.py Docstring whitespace cleanup.
astropy/​cosmology/​_src/​traits/​neutrino.py Improves property docstring wording to match style (“Whether …”).
astropy/​cosmology/​_src/​traits/​scale_factor.py Docstring whitespace cleanup.
astropy/​cosmology/​_src/​traits/​tcmb.py Docstring whitespace cleanup.
astropy/​cosmology/​_src/​parameter/​core.py Adds numpydoc ignore for dataclass-generated Parameter init docs; fills in missing parameter descriptions and improves capitalization.
astropy/​cosmology/​_src/​parameter/​converter.py Completes validator docstrings with parameter/return details.
astropy/​cosmology/​_src/​parameter/​descriptors.py Adds numpydoc ignore for dataclass-generated descriptor init docs.
astropy/​cosmology/​_src/​parameter/​utils.py Documents utility functions’ parameters/returns for validation.
astropy/​cosmology/​_src/​io/​connect.py Adds numpydoc ignores for unified I/O descriptor classes where signature/docs are provided via __call__.
astropy/​cosmology/​_src/​io/​builtin/​cosmology.py Documents identify helper parameters/returns for numpydoc compliance.
astropy/​cosmology/​_src/​io/​builtin/​ecsv.py Docstring punctuation fixes; documents identify helper parameters/returns.
astropy/​cosmology/​_src/​io/​builtin/​html.py Moves Notes into the expected location and documents return value; docstring formatting cleanup.
astropy/​cosmology/​_src/​io/​builtin/​latex.py Documents identify helper parameters/returns and fixes summary wording.
astropy/​cosmology/​_src/​io/​builtin/​mapping.py Documents helper functions and identify helper parameters/returns; punctuation fixes.
astropy/​cosmology/​_src/​io/​builtin/​model.py Adds missing parameter docs; documents identify helper parameters/returns.
astropy/​cosmology/​_src/​io/​builtin/​mrt.py Docstring formatting cleanup and signature/doc alignment work for MRT I/O helpers and identify function.
astropy/​cosmology/​_src/​io/​builtin/​row.py Docstring punctuation fixes; documents identify helper parameters/returns; parameter order fixes.
astropy/​cosmology/​_src/​io/​builtin/​table.py Docstring whitespace cleanup; adds missing return docs; documents identify helper parameters/returns.
astropy/​cosmology/​_src/​io/​builtin/​utils.py Adds missing parameter/return descriptions for I/O conversion helpers.
astropy/​cosmology/​_src/​io/​builtin/​yaml.py Docstring punctuation/wording fixes; adds missing parameter/return descriptions for constructors and registration helpers.

Review effort: Lite

Comment thread astropy/cosmology/parameters.py Resolved
Co-authored-by: Copilot Autofix powered by AI <[email protected]>

Copilot AI left a comment

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.

Note

Copilot was unable to complete this review at the selected tier due to model policy or plan restrictions.

🟡 Changes recommended

The change still has active findings: one introduces a runtime error by placing numpydoc section headers outside a docstring in __getattr__, and another leaves misleading docstring content/types for mrt_identify under enabled numpydoc validation.

1 open issue
2 resolved since last review

Review effort: Lite

Comment thread astropy/cosmology/parameters.py Resolved
Co-authored-by: Copilot Autofix powered by AI <[email protected]>

Copilot AI left a comment

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.

Note

Copilot was unable to complete this review at the selected tier due to model policy or plan restrictions.

🔵 Needs a closer look

Several identifier functions call filepath.endswith(...) even though UnifiedIORegistry may supply filepath as an os.PathLike (e.g., pathlib.Path), risking AttributeError at runtime, and there is also a stale docstring in mrt_identify that needs updating.

No open issues 🎉

3 previously missed issues

In code that hasn't changed since last review

Medium severity mrt_identify should handle pathlib.Path inputs

astropy/​cosmology/​_src/​io/​builtin/​ecsv.py:514

UnifiedIORegistry passes path as str or os.PathLike (see astropy/io/registry/core.py), so calling filepath.endswith(...) can raise AttributeError when filepath is a pathlib.Path. Consider accepting PathLike here and normalizing with str() (or os.fspath) before checking the suffix.

Medium severity filepath.endswith breaks on path-like inputs

astropy/​cosmology/​_src/​io/​builtin/​latex.py:215

UnifiedIORegistry can pass filepath as an os.PathLike (e.g. pathlib.Path). Using filepath.endswith(...) will fail for those inputs. Converting with str() (or os.fspath) avoids the AttributeError and makes the identifier work for path-like objects.

Medium severity mrt_identify docstring and path handling are outdated

astropy/​cosmology/​_src/​io/​builtin/​mrt.py:291

The mrt_identify docstring still says “HTML Table format”, and filepath.endswith(...) will raise AttributeError if filepath is an os.PathLike (e.g. pathlib.Path). UnifiedIORegistry can pass path-like objects as the path argument, so this identifier should normalize filepath (e.g. str(filepath) / os.fspath) before checking the suffix.

1 resolved since last review

Review effort: Lite

@pllim pllim added the Docs label Nov 4, 2026

>>> temp_dir.cleanup()

Notes

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.

Are you sure this isn't used in some fancy docstring injection during rendering?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I'll look. But if there is then we have a hole in the test suite.

@nstarman nstarman Nov 5, 2026 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I checked, and it's safe to remove. The I/O registry appends its table of formats to the Notes section of Cosmology.read and Cosmology.write. Those docstrings live in connect.py and are unchanged here. The empty Notes in write_mrt was just a leftover.

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.

Thanks for checking!

@pllim pllim left a comment

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.

Since you reviewed your agent's work, I won't do it again. Looks fine at a glance. Thanks.

@github-project-automation github-project-automation Bot moved this from In Progress to Reviewer approved in Cosmology, the Expansion Nov 5, 2026
@pllim
pllim merged commit d9643fb into astropy:main Nov 5, 2026
51 of 52 checks passed
@github-project-automation github-project-automation Bot moved this from Reviewer approved to Done in Cosmology, the Expansion Nov 5, 2026
@pllim

pllim commented Nov 5, 2026

Copy link
Copy Markdown
Member

xref #20353

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

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

3 participants