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.
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
pd.concatof DataFrames with arrow-backed dtypes (e.g.int32[pyarrow]) produces chunked arrays inside the pandas columns, sopa.array()returns aChunkedArrayfor those columns andRecordBatch.from_pandasfails withTypeError: Cannot convert pyarrow.lib.ChunkedArray to pyarrow.lib.Array(#41936).Table.from_pandasis unaffected becauseTable.from_arraysaccepts chunked arrays.What changes are included in this PR?
RecordBatch.from_pandasnow combines the chunked arrays withChunkedArray.combine_chunks()before callingRecordBatch.from_arrays.Table.from_pandaskeeps its chunked columns unchanged (no copying added on that path).Are these changes tested?
test_recordbatch_from_pandas_concatenated_arrow_backedintest_pandas.py, which fails without this change (verified locally against an installed pyarrow 24.0.0 wheel) and passes with it (CI).ChunkedArray, andcombine_chunks()returns a singleInt32Arraywith the expected values and type.Are there any user-facing changes?
RecordBatch.from_pandasnow works for DataFrames containing chunked arrow-backed columns instead of raisingTypeError.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. The bug was reproduced locally with pandas 3.0.2 + pyarrow 24.0.0, the conversion path was traced (
__arrow_array__returns a singleArrayfor a single-chunk column and aChunkedArrayafterpd.concat), and the exact transformation (combine_chunks()) was verified locally on the reproduced objects. The Cython wiring itself is exercised by the regression test in CI.