Repository navigation
Conversation
…andas pd.concat of DataFrames with arrow-backed dtypes produces chunked arrays inside the pandas columns, so pa.array() returns a ChunkedArray for those columns and RecordBatch.from_pandas failed with "TypeError: Cannot convert pyarrow.lib.ChunkedArray to pyarrow.lib.Array". Table.from_pandas is unaffected because Table.from_arrays accepts chunked arrays. Combine the chunked arrays into single arrays with ChunkedArray.combine_chunks() before calling RecordBatch.from_arrays. Table.from_pandas keeps its chunked columns unchanged. Added a regression test in test_pandas.py.
The docstring claimed that a NumPy copy is always returned, but for a single chunk without nulls a zero-copy read-only view of the Arrow buffers is returned even with zero_copy_only=False, while copies are made for multiple chunks or in the presence of nulls. This explains the OWNDATA/WRITEABLE flags reported in the issue: a view is not writable (Arrow data is immutable), and a copy does not own its data either because the underlying buffer is owned by the memory pool allocation wrapped as the NumPy base. Document the actual view-or-copy behavior, the flag semantics, and how to obtain an owned writable array.
Member
|
Closing this PR as it doesn't meet our guidelines on AI-generated contributions: https://arrow.apache.org/docs/developers/overview.html#ai-generated-code If you'd like to contribute this change, please review and test the code yourself, then open a new PR. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Rationale for this change
The
ChunkedArray.to_numpydocstring 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 thoughzero_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_numpydocstring to describe the actual behavior:ValueError: assignment destination is read-onlybecause Arrow data is immutable..copy()is the reliable way to obtain an array that is safe to modify.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, please disclose below whether and how AI was used in this PR.
PR code and description written by:
Reviewed before submission by:
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.