Skip to content

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

In progress

Description

@PatrikBernhard

Describe the bug, including details regarding any error messages, version, and platform.

>>> import pandas as pd
>>> pd.__version__ 
'2.2.2'
>>> import pyarrow as pa
>>> pa.__version__
'16.1.0'
>>> df = pd.DataFrame({"1": [1]}).astype({"1": "int32[pyarrow]"})
>>> concat_df = pd.concat([df, df])
>>> pa.RecordBatch.from_pandas(df)
pyarrow.RecordBatch
1: int32
----
1: [1]

>>> pa.RecordBatch.from_pandas(concat_df)

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "pyarrow/table.pxi", line 3289, in pyarrow.lib.RecordBatch.from_pandas
  File "pyarrow/table.pxi", line 3379, in pyarrow.lib.RecordBatch.from_arrays
TypeError: Cannot convert pyarrow.lib.ChunkedArray to pyarrow.lib.Array

This has been observed on my macOS Sonoma 14.5 as well as on a server running linux.

Component(s)

Python

Activity

  1. added this to the 17.0.0 milestone on Jun 9, 2024
  2. jorisvandenbossche commented on Jun 11, 2024

    @jorisvandenbossche
    Member

    @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: Cannot convert pyarrow.lib.ChunkedArray to pyarrow.lib.Array
  3. removed this from the 17.0.0 milestone on Jun 11, 2024
  4. thisisnic commented on Nov 25, 2026

    @thisisnic
    Member

    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:

    import pandas as pd
    import pyarrow as pa
    
    df = pd.DataFrame({"s": ["a", "b"]})
    pa.RecordBatch.from_pandas(pd.concat([df, df]))
    # pandas 2.3.3: works
    # pandas 3.1.1: TypeError: Cannot convert pyarrow.lib.ChunkedArray to pyarrow.lib.Array

    pa.Table.from_pandas() works in both cases. Integer columns are unaffected unless they use an Arrow-backed dtype, as in the original report.

  5. added
    Status: confirmed
    on Nov 25, 2026
  6. sameer727 commented on Nov 27, 2026

    @sameer727

    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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Component: PythonStatus: confirmedType: bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions