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
pyarrow.RecordBatch.from_pandas fails on concatenated pandas.DataFrames: TypeError: Cannot convert pyarrow.lib.ChunkedArray to pyarrow.lib.Array #41936
@PatrikBernhard the issue here is that your example pandas DataFrame consists of a chunked column (because of the concat step), and a RecordBatch is a data structure where each column consists of a single contiguous array.
In pyarrow, that's the difference between a RecordBatch and a Table (RecordBatch being a collection of Array objects, and a Table a collection of ChunkedArray objects).
So you will noticed that pa.Table.from_pandas(concat_df) works fine.
Historically, pandas DataFrames always had columns that used a single non-chunked array under the hood, and that's the reason that RecordBatch.from_pandas currently does not support that.
I am not entirely sure what the best solution is: keep raising the error (but maybe make it more informative or document this behaviour better) because people might not expect a copy in this conversion step, or automatically converting the chunked array to a contiguous array.
As a comparison, directly constructing a RecordBatch from a ChunkedArray gives the same error:
In [10]: arr=pa.chunked_array([pa.array([1], pa.int32()), pa.array([2], pa.int32())])
In [11]: pa.RecordBatch.from_arrays([arr], names=["col"])
...
TypeError: Cannotconvertpyarrow.lib.ChunkedArraytopyarrow.lib.Array
Opened a PR for this: #55820 — it implements the second of the two options mentioned in the thread (automatically combining the chunked arrays via ChunkedArray.combine_chunks() in RecordBatch.from_pandas, leaving Table.from_pandas chunked as before). With pandas 3 making ordinary string columns arrow-backed, the concatenated case now fails for plain string columns too, so the auto-conversion seemed worth proposing over a more informative error; happy to switch if the copy behavior is a concern.
Activity
jorisvandenbossche commentedon Jun 11, 2024
@PatrikBernhard the issue here is that your example pandas DataFrame consists of a chunked column (because of the concat step), and a RecordBatch is a data structure where each column consists of a single contiguous array.
In pyarrow, that's the difference between a
RecordBatchand aTable(RecordBatch being a collection ofArrayobjects, and a Table a collection ofChunkedArrayobjects).So you will noticed that
pa.Table.from_pandas(concat_df)works fine.Historically, pandas DataFrames always had columns that used a single non-chunked array under the hood, and that's the reason that
RecordBatch.from_pandascurrently does not support that.I am not entirely sure what the best solution is: keep raising the error (but maybe make it more informative or document this behaviour better) because people might not expect a copy in this conversion step, or automatically converting the chunked array to a contiguous array.
As a comparison, directly constructing a RecordBatch from a ChunkedArray gives the same error:
thisisnic commentedon Nov 25, 2026
I used an AI agent to rerun this on current releases, and I've reviewed the results.
🤖 :
This still happens on pyarrow 26.0.1, and with pandas 3 it now affects ordinary string columns, since those are Arrow-backed by default:
pa.Table.from_pandas()works in both cases. Integer columns are unaffected unless they use an Arrow-backed dtype, as in the original report.sameer727 commentedon Nov 27, 2026
Opened a PR for this: #55820 — it implements the second of the two options mentioned in the thread (automatically combining the chunked arrays via
ChunkedArray.combine_chunks()inRecordBatch.from_pandas, leavingTable.from_pandaschunked as before). With pandas 3 making ordinary string columns arrow-backed, the concatenated case now fails for plain string columns too, so the auto-conversion seemed worth proposing over a more informative error; happy to switch if the copy behavior is a concern.