astral-sh / astral-sh/python-build-standalone

Heinsenbug seen against numpy + python-build-standalone builds on Linux

Open
#934 5 comments 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
4.4k
Forks
314
Avg merge
1d 9h
Merged PRs (30d)
27

Description

I'm seeing a spurious warning from a C extension in numpy, that only appears when running a pre-built interpreter from python-build-standalone (as far as I can tell).

```py
# t.py
from astropy.coordinates import Angle
from astropy.units import degree

angle = Angle("1.0", unit=degree)
angle.to_string()
```

run with `uv run python -Werror t.py`

```python-traceback
Traceback (most recent call last):
File "/home/clm/dev/gh/astropy/astropy/t.py", line 5, in
angle.to_string()
~~~~~~~~~~~~~~~^^
File "/home/clm/dev/gh/astropy/astropy/astropy/coordinates/angles/core.py", line 387, in to_string
result = format_ufunc(self.to_value(unit))
File "/home/clm/dev/gh/astropy/astropy/.venv/lib/python3.14/site-packages/numpy/lib/_function_base_impl.py", line 2518, in __call__
return self._call_as_normal(*args, **kwargs)
~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^
File "/home/clm/dev/gh/astropy/astropy/.venv/lib/python3.14/site-packages/numpy/lib/_function_base_impl.py", line 2511, in _call_as_normal
return self._vectorize_call(func=func, args=vargs)
~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^
File "/home/clm/dev/gh/astropy/astropy/.venv/lib/python3.14/site-packages/numpy/lib/_function_base_impl.py", line 2600, in _vectorize_call
outputs = ufunc(*args, out=...)
RuntimeWarning: invalid value encountered in do_format (vectorized)

```
It's a bit opaque since both numpy and astropy's internal logic is involved, and I'm 99% sure astropy isn't actually needed to reproduce (I'll be trying to eliminate this bit shortly), but here are a couple key details:
- `astropy.coordinates.Angle.to_string` runs an internal closure that's produced from `np.vectorize`
- my understanding is that this warning normally corresponds to an invalid (nan) is received. Here the only value that is actually passed to the vectorized closure is `np.ndarray(np.float64(1.0), dtype=object)`

I discovered this in CI, and I'm able to reproduce this locally under the following conditions:
- run on Linux: I can't reprod on macOS
- run with a release-build of numpy (either a wheel or a local build with default settings): the warning disappears when numpy is compiled in debug mode
- all versions of Python I tested are affected
- but only builds from python-build-standalone (that I use via uv): if I build my own interpreter locally, or if I switch to `actions/setup-python` in CI, no warning is emitted.

Furthermore, my CI started failing with this warning on dec 20. My last successful job ran on dec 18. I'm surprised to see that uv didn't get a release since dec 9. Maybe my mental model for how python-build-standalone is used in uv is just wrong; I was working under the assumption no changes here would affect uv before it was mirrored (upgraded) there.

I'm very much out of my depth and currently out of ideas about where the problem might be coming from exactly, but I only see it with this project's relocatable builds of Python so this is where I'm starting my quest for help. I'll attempt to minimize my reproducer now.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.