decitre opened a new issue, #55734:
URL: https://github.com/apache/arrow/issues/55734
### Describe the bug, including details regarding any error messages,
version, and platform.
### Describe the bug
On a 32-bit WebAssembly build (xeus-python in JupyterLite, packages from
emscripten-forge), `pa.array()` of a numpy `int32` array returns an `int64`
Arrow array with wrong values. Arrow appears to read the `int32` buffer as
64-bit integers. As a consequence `Array.take()` / `ChunkedArray.take()` with
numpy indices raises `ArrowIndexError`.
The same code works with `int64` indices or a Python list.
### Reproducer
```python
import numpy as np
import pyarrow as pa
x = np.array([0, 2], dtype=np.int32)
a = pa.array(x)
print(a.type, a.to_pylist())
# actual: int64 [8589934592, 68719476738]
# expected: int32 [0, 2]
arr = pa.chunked_array([pa.array(["a", "b", "c"])])
arr.take(x)
# ArrowIndexError: Index 8589934592 out of bounds
```
Other index inputs, same session:
| Indices | Result |
|---|---|
| `np.array([0, 2], dtype=np.int32)` | `ArrowIndexError: Index 8589934592
out of bounds` |
| `np.array([0, 2], dtype=np.intp)` | `ArrowIndexError: Index 8589934592 out
of bounds` |
| `pa.array(np.array([0, 2], dtype=np.int32))` | `ArrowIndexError: Index
8589934592 out of bounds` |
| `np.array([0, 2], dtype=np.int64)` | `['a', 'c']` |
| `[0, 2]` (Python list) | `['a', 'c']` |
On this platform `sys.maxsize == 2147483647`, and `np.intp`,
`np.arange(...)` and `np.delete(...)` all return `int32`. Any code that passes
numpy indices to `take` is affected.
### Impact
pandas 3 stores string column labels in pyarrow, so ordinary pandas calls
fail. For example, `GeoDataFrame.__geo_interface__` (GeoPandas 1.2.0) calls
`columns.drop("geometry")`, which goes through `ExtensionArray.delete` and
`ArrowExtensionArray.take`:
```
File pandas/core/arrays/base.py:2651, in ExtensionArray.delete
indexer = np.delete(np.arange(len(self)), loc)
return self.take(indexer)
File pandas/core/arrays/arrow/array.py:2327, in ArrowExtensionArray.take
return self._from_pyarrow_array(self._pa_array.take(indices_array))
ArrowIndexError: Index 19137309119086592 out of bounds
```
### Environment
- Runtime: xeus-python (JupyterLite), Chromium, 32-bit WebAssembly
- pyarrow 23.0.0
- numpy 2.5.4
- pandas 3.1.0
- geopandas 1.2.0
### Comparison
A Pyodide-based JupyterLite site with pyarrow 22.0.0, numpy 2.4.6 and pandas
3.0.2 runs the same pandas/GeoPandas call without error. I have not run the
minimal `pa.array(np.int32)` reproducer there.
### Question
I can't tell whether the conversion bug is in PyArrow's numpy-to-Arrow dtype
mapping or in how the emscripten-forge build is configured (a `long`/`intp`
width assumption on wasm32). Upstream CI already builds and tests PyArrow
against Pyodide, so a missing patch in the emscripten-forge recipe, or a recent
regression, is possible.
### Workaround
Pass `int64` indices or a Python list to `take`, or avoid pyarrow-backed
strings (for example `pd.options.mode.string_storage = "python"`).
### Component(s)
Python
--
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]