Skip to content

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

@neutrinoceros

Description

@neutrinoceros

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

# 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

Traceback (most recent call last):
  File "/home/clm/dev/gh/astropy/astropy/t.py", line 5, in <module>
    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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions