You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Python][Docs] ChunkedArray.to_numpy() sets the OWNDATA and WRITEABLE flags to False #38789
The docs say: "Introduced for signature consistence with pyarrow.Array.to_numpy. This must be False here since NumPy arrays’ buffer must be contiguous."
As we are returning a copy, OWNDATA and WRITEABLE should be True.
Thank you for opening an issue and sorry for such a late reply!
I agree, the documentation for ChunkedArray.to_numpy is a bit misleading. But the behaviour should actually be correct!
The example you are using in the issue description is a special case as the chunked array consists only of one chunk and can therefore be converted to numpy zero copy:
In [1]: importpyarrowaspaIn [2]: arr=pa.chunked_array([[1.1]])
In [3]: arr.to_numpy(zero_copy_only=False).base.baseOut[3]:
<pyarrow.lib.ChunkedArrayobjectat0x105329170>
[
[
1.1
]
]
In [4]: arrOut[4]:
<pyarrow.lib.ChunkedArrayobjectat0x105329170>
[
[
1.1
]
]
which means the code in PyArrow that checks for zero_copy_only=False should be changed to allow zero copy in case of a single chunk together with the docs for zero_copy_only attribute:
Introduced for signature consistence with pyarrow.Array.to_numpy.
This must be False here since NumPy arrays' buffer must be contiguous.
But the flags OWNDATA : False and WRITEABLE : False are correct.
Now if the chunked array has more than one chunk, the WRITEABLE flag is different but OWNDATA is still false as Arrow is holding on to the memory of the Buffer created with the copy:
In [5]: arr=pa.chunked_array([[1.1], [2.2]])
In [6]: arr.to_numpy(zero_copy_only=False).base.baseOut[6]: <capsuleobject"arrow::Buffer"at0x10a017b10>
Change the docstring for zero_copy_only parameter and change the check for this parameter in ChunkedArray.to_numpy for chunked arrays with only one chunk.
Your contribution would be more than welcome, thanks!
changed the title [-]ChunkedArray.to_numpy() sets the OWNDATA and WRITEABLE flags to False[/-][+][Python][Docs] ChunkedArray.to_numpy() sets the OWNDATA and WRITEABLE flags to False[/+]on Feb 7, 2024
Activity
alippai commentedon Nov 23, 2023
Cc @AlenkaF @jorisvandenbossche
alippai commentedon Feb 6, 2024
Gentle ping @AlenkaF @jorisvandenbossche
I'm not sure what to look for, but if you point me into the right direction I could possibly help.
AlenkaF commentedon Feb 7, 2024
Thank you for opening an issue and sorry for such a late reply!
I agree, the documentation for
ChunkedArray.to_numpyis a bit misleading. But the behaviour should actually be correct!The example you are using in the issue description is a special case as the chunked array consists only of one chunk and can therefore be converted to numpy zero copy:
which means the code in PyArrow that checks for
zero_copy_only=Falseshould be changed to allow zero copy in case of a single chunk together with the docs forzero_copy_onlyattribute:arrow/python/pyarrow/table.pxi
Lines 498 to 501 in a6e577d
arrow/python/pyarrow/table.pxi
Lines 481 to 485 in a6e577d
But the flags
OWNDATA : FalseandWRITEABLE : Falseare correct.Now if the chunked array has more than one chunk, the
WRITEABLEflag is different butOWNDATAis still false as Arrow is holding on to the memory of the Buffer created with the copy:To sum up, what I think we should do is:
pyarrow.Array.to_numpy." . The "experimental" should also be removed =)zero_copy_onlyparameter and change the check for this parameter inChunkedArray.to_numpyfor chunked arrays with only one chunk.Your contribution would be more than welcome, thanks!
[-]ChunkedArray.to_numpy() sets the OWNDATA and WRITEABLE flags to False[/-][+][Python][Docs] ChunkedArray.to_numpy() sets the OWNDATA and WRITEABLE flags to False[/+]sameer727 commentedon Nov 27, 2026