apache / apache/arrow

[Python] Single chunk ChunkedArray doesn't correctly respect copy in __array__method

Open
#49,384 3 comments 0 reactions 1 assignee Claimed by @jingyi-zhao-01 View on GitHub
Component: Python Type: bug
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.

The expectation is that if `copy=True` is passed into the `__array__` method, the returned numpy array should be writable. This is true if the chunked array contains more than one chunk, but if the array contains a single chunk the returned array is not writable.

The below code:
```python
pyarrow.chunked_array([[2, 3]]).__array__(copy=True).flags
```
Returns:
```
C_CONTIGUOUS : True
F_CONTIGUOUS : True
OWNDATA : False
WRITEABLE : False
ALIGNED : True WRITEBACKIFCOPY : False
```

I originally discovered this when `numpy.array(chunked_array)` returned a read-only array.

Environment:
Python: 3.13.0
OS: Linux
PyArrow version: 23.0.1

### Component(s)

Python

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.