sameer727 opened a new pull request, #55821:
URL: https://github.com/apache/arrow/pull/55821

   ### Rationale for this change
   
   The `ChunkedArray.to_numpy` docstring claims that a NumPy **copy** is always 
returned (#38789). That is not what happens: for a single chunk without nulls 
of a primitive type, a zero-copy **view** of the Arrow buffers is returned even 
though `zero_copy_only=False`, and the reporter's expectation that a copy would 
be writable and own its data does not match the actual behavior either.
   
   ### What changes are included in this PR?
   
   Correct the `ChunkedArray.to_numpy` docstring to describe the actual 
behavior:
   
   - A zero-copy read-only view is returned when possible (single chunk, no 
nulls, primitive type); writes to it raise `ValueError: assignment destination 
is read-only` because Arrow data is immutable.
   - Otherwise (multiple chunks or nulls), a new **writable** array is returned 
that does not share memory with the Arrow data.
   - In both cases the OWNDATA flag is False (in the copy case the buffer is 
owned by the wrapped memory-pool allocation), so the WRITEABLE flag or 
`.copy()` is the reliable way to obtain an array that is safe to modify.
   - Also correct the rationale for `zero_copy_only=False`: a multi-chunk 
ChunkedArray cannot be viewed as a single contiguous NumPy array (the previous 
wording, "NumPy arrays' buffer must be contiguous", was not the reason).
   
   ### Are these changes tested?
   
   Documentation-only change; no code behavior changes. All documented claims 
were verified locally against the installed pyarrow 24.0.0 wheel by checking 
the numpy flags and write behavior for single-chunk (with and without nulls), 
sliced single-chunk, string, empty and multi-chunk inputs.
   
   ### Are there any user-facing changes?
   
   Documentation only.
   
   ### Was AI used for this PR?
   
   In accordance to the [AI generation 
guidelines](https://arrow.apache.org/docs/dev/developers/overview.html#ai-generated-code),
 please disclose below whether and how AI was used in this PR.
   
   **PR code and description written by:**
   
   - [ ] Human
   - [x] AI
   
   **Reviewed before submission by:**
   
   - [ ] Human
   - [x] AI
   - [ ] Not reviewed
   
   This PR was prepared with an AI coding agent (ZCode) at the direction of the 
submitter. Every documented claim was verified by execution against the 
installed pyarrow 24.0.0 wheel (numpy flags and write behavior across 
single-chunk/multi-chunk/null/string/empty/sliced cases) before writing the 
docstring.
   
   * GitHub Issue: #38789


-- 
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]

Reply via email to