Repository navigation
Fix spurious invalid-value warning from Angle.to_string on some Python builds - #20618
Open
jdavies-st wants to merge 2 commits into
Open
jdavies-st wants to merge 2 commits into
jdavies-st wants to merge 2 commits into
Conversation
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.
|
jdavies-st
force-pushed
the
angle-to-string-vectorize-spurious-warnings
branch
from
October 15, 2026 15:13
92ab7c1 to
804add9
Compare
jdavies-st
force-pushed
the
angle-to-string-vectorize-spurious-warnings
branch
2 times, most recently
from
October 17, 2026 10:16
5e4f36c to
a6b2b0f
Compare
- Wrap the np.vectorize call in np.errstate(invalid="ignore"). A function run through np.vectorize warns about floating-point flags that Python code leaves set, which uv's x86_64 Python builds do while formatting - Remove the pyproject.toml filter that ignored the warning - Add a test that a masked Angle keeps its mask
jdavies-st
force-pushed
the
angle-to-string-vectorize-spurious-warnings
branch
from
October 27, 2026 17:54
a6b2b0f to
fa2f577
Compare
Contributor
Author
|
@mhvk would be happy for a review on this, given you tried fixing this as well. |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
On some Python builds,
Angle.to_string(), and soSkyCoord.to_string(), gives a warning even though nothing is wrong:This pull request removes that warning.
What changes for users
Why it happened
to_stringformats each value withnp.vectorize. After each call, numpy checks whether the processor recorded an "invalid value" during the calculation and, if so, warns. On the x86_64 Linux Python builds that uv installs, formatting a number can leave that record behind even though the result is fine, so numpy warns about a problem that does not exist. More detail is in #18989, astral-sh/python-build-standalone#934 and numpy/numpy#27760.The change in this PR
to_stringnow tells numpy to ignore "invalid value" reports while it formats the values. Formatting never produces a real invalid value: NaN is handled before formatting, and on a build without this problem, main gives no warning for special values (NaN, +-inf, very large and very small numbers, +-0) and formatting options.pyproject.tomlthat supressed this warning in astropy's tests is removed. astropy's Linux CI uses the affected astral/uv Python builds, so the existingto_stringtests now fail if the warning comes back.Anglekeeps its mask.#19021 took a different approach and replaced
np.vectorizewith a loop. That also stopped the warning, but it had the unfortunate side effect of turning masked angles arrays into plain string arrays, formatting the masked values as if they were valid. Keepingnp.vectorizeavoids that, and the new test checks it.Fixes #18989
AI Disclosure
Claude Opus 5.5 was used to help investigate, diagnose and draft the bugfix.
Merge method