You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@arrow.apache.org by "BenLewis-Seequent (via GitHub)" <gi...@apache.org> on 2026/02/24 20:06:48 UTC
[I] Single chunk ChunkedArray doesn't correctly respect copy in __array__method [arrow]
BenLewis-Seequent opened a new issue, #49384:
URL: https://github.com/apache/arrow/issues/49384
### 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
--
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: issues-unsubscribe@arrow.apache.org.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [I] [Python] Single chunk ChunkedArray doesn't correctly respect copy in __array__method [arrow]
Posted by "raulcd (via GitHub)" <gi...@apache.org>.
raulcd commented on issue #49384:
URL: https://github.com/apache/arrow/issues/49384#issuecomment-5023827356
This seems to have been closed by mistake.
--
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: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [I] [Python] Single chunk ChunkedArray doesn't correctly respect copy in __array__method [arrow]
Posted by "thisisnic (via GitHub)" <gi...@apache.org>.
thisisnic closed issue #49384: [Python] Single chunk ChunkedArray doesn't correctly respect copy in __array__method
URL: https://github.com/apache/arrow/issues/49384
--
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: issues-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [I] [Python] Single chunk ChunkedArray doesn't correctly respect copy in __array__method [arrow]
Posted by "jingyi-zhao-01 (via GitHub)" <gi...@apache.org>.
jingyi-zhao-01 commented on issue #49384:
URL: https://github.com/apache/arrow/issues/49384#issuecomment-5010542207
I can still reproduce this on current Arrow main / local PyArrow dev build:
- pyarrow `26.0.0.dev3+gb03b4c539`
- numpy `2.5.1`
Minimal repro:
```python
import numpy as np
import pyarrow as pa
for arr in [pa.chunked_array([[2, 3]]), pa.chunked_array([[2], [3]])]:
out = np.array(arr, copy=True)
print(arr.num_chunks, out.flags.owndata, out.flags.writeable)
try:
out[0] = 99
print("mutation ok", out.tolist())
except Exception as exc:
print(type(exc).__name__, exc)
```
Observed output:
```text
1 False False
ValueError assignment destination is read-only
2 False True
mutation ok [99, 3]
```
So this still matches the earlier analysis: the single-chunk path can return a zero-copy read-only NumPy view even when `copy=True`, while the multi-chunk path materializes a writable array.
Minimal ask: if nobody is currently working on it, I can take a shot at a small regression test plus a narrow fix in `ChunkedArray.__array__` to make the single-chunk path respect `copy=True`.
--
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: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [I] Single chunk ChunkedArray doesn't correctly respect copy in __array__method [arrow]
Posted by "AlenkaF (via GitHub)" <gi...@apache.org>.
AlenkaF commented on issue #49384:
URL: https://github.com/apache/arrow/issues/49384#issuecomment-4134014162
Thank you for opening the issue, looks like this indeed is a bug.
After doing some investigating, it looks like this happens when chunked array has only one chunk and can therefore be zero-copied (no missing values, etc.):
```python
>>> np.array(pa.chunked_array([[1, 2, 3]]), copy=True).flags.writeable
False
>>> np.array(pa.chunked_array([[1, 2], [3]]), copy=True).flags.writeable
True
```
The comment in the code:
https://github.com/apache/arrow/blob/560ef02158131487b54cfb1f3883def10d9a67a7/python/pyarrow/table.pxi#L558
is valid for chunked arrays with number of chunks > 0. Otherwise the code needs to take into account the copy flag.
I think the PR for this should be quite straightforward, contributions are most welcome!
--
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: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org