mohamd764 commented on issue #53954:
URL: https://github.com/apache/arrow/issues/53954#issuecomment-6221951390

   I can confirm the behaviour and the version boundary (Python 3.12.15, Linux 
x86_64, `uv pip install`):
   
   | pyarrow | numpy 1.26.4 |
   |---|---|
   | 21.0.0, 22.0.0, 23.0.1, 24.0.0, 25.0.1 | `import pyarrow` works, 
`pa.array(np.arange(3)).to_numpy()` works |
   | 26.0.0 | `ImportError: pyarrow requires NumPy 2.0 or newer, found 1.26.4` |
   
   The 26.0.0 wheel's `METADATA` has no `Requires-Dist` lines at all, so pip/uv 
have nothing to resolve against.
   
   Some context in case it helps: this was an intentional change for 26.0.0 in 
#50769 (GH-48473, "Require numpy 2.0"). The check is in `pyarrow/lib.pyx` 
(lines 40-45 at `apache-arrow-26.0.0`) and only runs if `import numpy` 
succeeds. NumPy is still an optional runtime dependency. With numpy 
uninstalled, pyarrow 26.0.0 imports fine, and a Parquet write/read round trip 
and `pc.sum` work. That's probably why there's no runtime requirement. Adding 
`numpy>=2` to `[project].dependencies` (what #53971 proposed; it was closed 
without being merged) would make numpy mandatory for everyone, and package 
metadata has no way to say "numpy>=2, but only if numpy is installed".
   
   The [install docs for 
26.0.0](https://arrow.apache.org/docs/python/install.html#dependencies) already 
list "NumPy 2.0 or higher" under *optional* dependencies, which matches this 
behaviour.
   
   Practical options for now: `pip install "numpy>=2"` alongside pyarrow 26, or 
pin `pyarrow<26` if you need to stay on NumPy 1.x. On the user side, a 
constraints file with `numpy>=2` also does the job. I tried this in a fresh 
Python 3.12 venv with `-c constraints.txt`:
   
   - `pyarrow==26.0.0` alone: numpy is not installed
   - `pyarrow==26.0.0 "numpy<2"`: resolution fails (pip and uv both)
   - `pyarrow==26.0.0 pandas==2.2.3`: numpy 2.5.4 is picked (uv)
   
   A constraint doesn't upgrade a numpy 1.x that's already installed if you 
only install pyarrow, though (checked with uv). In that case you still have to 
upgrade numpy yourself.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to