Skip to content

Load CODATA constants from text files#19786

Draft
jomigmonte wants to merge 3 commits into
astropy:mainfrom
jomigmonte:fix-issue-3843
Draft

Load CODATA constants from text files#19786
jomigmonte wants to merge 3 commits into
astropy:mainfrom
jomigmonte:fix-issue-3843

Conversation

@jomigmonte
Copy link
Copy Markdown

Description

This pull request migrates CODATA constants to be loaded from versioned .txt files via a dedicated parser, similar to SciPy’s approach.

Changes:
-Added codata_parser.py with dedicated tests
-Added CODATA .txt files for all supported years
-Updated the corresponding codata20XX.py modules to read constants from those files (while keeping derived constants computed in code)

Fixes #3843

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

m_p_entry.value,
m_p_entry.unit,
m_p_entry.uncertainty,
system="si",
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.

This seems like a lot of repeated boilerplate code - there must be a way to factor this out into a helper?

@astrofrog
Copy link
Copy Markdown
Member

If we are serious about doing this we will need to audit all the values before/after this PR to make sure they are identical

@astrofrog
Copy link
Copy Markdown
Member

While I think of it we should also assess the impact on import time of reading all these files

@mhvk
Copy link
Copy Markdown
Contributor

mhvk commented May 21, 2026

Thanks for the PR! I like the idea, but we need to think a bit more how we implement it. Like @astrofrog, I wonder about the duplication. It might be nice to have a function to look up any constant by name, and get a Constant back. This can then be used in the code to look up the currently defined constants, but allows a user to get any other.

Note that a separate question is whether we are not duplicating too much what scipy does (although it of course does not have the Constant class). Should we vendor their parser? Finally make scipy a required dependency?

@pllim pllim added this to the v8.1.0 milestone May 21, 2026
@pllim pllim marked this pull request as draft May 21, 2026 16:17
@pllim
Copy link
Copy Markdown
Member

pllim commented May 21, 2026

Might be good to discuss at the Coordination meeting (astropy/astropy-project#535)? Also xref #12448 for scipy dependency discussion

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.

What constants to have and which to calculate

4 participants