[Python] Incorrect importing of buffer protocol objects
- Dominant language
- C++
- Stars
- 17.1k
- Forks
- 4.3k
- Avg merge
- 3d 13h
- Merged PRs (30d)
- 88
Description
### Describe the bug, including details regarding any error messages, version, and platform.
pyarrow seems to be applying some upcasting when importing data via the buffer protocol. This was unexpected behavior to me and could be considered a bug.
pyarrow seems to cast:
- `float32` -> `float64`
- `int32` -> `int64`
- `uint64` -> `int64`
As expected:
```py
import numpy as np
import pyarrow as pa
arr = np.array([1.0, 2.0, 3.0], dtype=np.float64)
pa.array(memoryview(arr))
#
# [
# 1,
# 2,
# 3
# ]
```
Unexpected casts:
```py
arr = np.array([1.0, 2.0, 3.0], dtype=np.float32)
pa.array(memoryview(arr))
#
# [
# 1,
# 2,
# 3
# ]
arr = np.array(object=[1.0, 2.0, 3.0], dtype=np.uint64)
pa.array(memoryview(arr))
#
# [
# 1,
# 2,
# 3
# ]
arr = np.array(object=[1.0, 2.0, 3.0], dtype=np.uint32)
pa.array(memoryview(arr))
#
# [
# 1,
# 2,
# 3
# ]
```
### Component(s)
Python
Contributor guide
Assessment
This issue has not been assessed yet.