Skip to content

GH-41936: [Python] Combine chunked arrays in RecordBatch.from_pandas - #55820

Closed
sameer727 wants to merge 1 commit into
apache:mainfrom
sameer727:recordbatch-from-pandas-chunked-41936
Closed

sameer727 wants to merge 1 commit into
apache:mainfrom
sameer727:recordbatch-from-pandas-chunked-41936

Conversation

@sameer727

@sameer727 sameer727 commented Nov 27, 2026 •

Copy link
Copy Markdown

Rationale for this change

pd.concat of DataFrames with arrow-backed dtypes (e.g. int32[pyarrow]) produces chunked arrays inside the pandas columns, so pa.array() returns a ChunkedArray for those columns and RecordBatch.from_pandas fails with TypeError: Cannot convert pyarrow.lib.ChunkedArray to pyarrow.lib.Array (#41936). Table.from_pandas is unaffected because Table.from_arrays accepts chunked arrays.

What changes are included in this PR?

RecordBatch.from_pandas now combines the chunked arrays with ChunkedArray.combine_chunks() before calling RecordBatch.from_arrays. Table.from_pandas keeps its chunked columns unchanged (no copying added on that path).

Are these changes tested?

  • Added a regression test test_recordbatch_from_pandas_concatenated_arrow_backed in test_pandas.py, which fails without this change (verified locally against an installed pyarrow 24.0.0 wheel) and passes with it (CI).
  • The transformation applied by the fix was verified locally on the exact repro: the concatenated column converts to a 2-chunk ChunkedArray, and combine_chunks() returns a single Int32Array with the expected values and type.
  • The change itself is in Cython, so the final wiring is exercised by the added test in CI.

Are there any user-facing changes?

RecordBatch.from_pandas now works for DataFrames containing chunked arrow-backed columns instead of raising TypeError.

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:

  • Human
  • AI

Reviewed before submission by:

  • Human
  • AI
  • Not reviewed

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 single Array for a single-chunk column and a ChunkedArray after pd.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.

…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.
Copilot AI balanced review requested due to automatic review settings November 27, 2026 19:55

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

@thisisnic

Copy link
Copy Markdown
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.

@thisisnic thisisnic closed this Nov 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

pyarrow.RecordBatch.from_pandas fails on concatenated pandas.DataFrames: TypeError: Cannot convert pyarrow.lib.ChunkedArray to pyarrow.lib.Array

3 participants