Skip to content

[Python] pa.Table.to_pandas(zero_copy_only=True) never succeeds #39194

Open

Description

@zblz

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

When converting a Table to pandas, adding the zero_copy_only=True argument makes it always fail with ArrowInvalid.

In [17]: table = pa.table({'a': [1.0, 2.0, 3.0], 'b': ['x','y','z']})

In [19]: table.schema
Out[19]: 
a: double
b: string

In [20]: table.to_pandas(zero_copy_only=True)
...
ArrowInvalid: Cannot do zero copy conversion into multi-column DataFrame block

Note that this is a similar bug report to #38644, but in that case the interaction with types_mapper is considered to be the reason for the Exception, whereas I found it is happening even without setting type mapping.

The keyword works fine for ChunkedArray conversions:

In [23]: table['a'].to_pandas(zero_copy_only=True)
Out[23]: 
0    1.0
1    2.0
2    3.0
Name: a, dtype: float64

even when adding type mapping to pandas Arrow types:

In [22]: table['a'].to_pandas(zero_copy_only=True, types_mapper=pd.ArrowDtype)
Out[22]: 
0    1.0
1    2.0
2    3.0
Name: a, dtype: double[pyarrow]

and fails on non-zero copy operations, like string to categorical conversion:

In [28]: table['b'].to_pandas(zero_copy_only=True, strings_to_categorical=True)
ArrowInvalid: Need to dictionary encode a column, but only zero-copy conversions allowed

Is this expected behaviour? I.e., should the argument always flag Table -> DataFrame conversions as not being zero copy? In that case, it might make sense to remove the argument from pa.Table.to_pandas altogether, as it will always result in an exception thrown.

Component(s)

Python

Activity

  1. akotlar commented on Apr 3, 2024

    @akotlar

    Running into the same issue

  2. trendelkampschroer commented on Jul 5, 2024

    @trendelkampschroer

    Same error here, for very simple types.

    frame_ = pd.DataFrame({"A": [1, 2, 3], "B": [4., 5., 6.]})
    frame = pl.from_pandas(frame_)
        frame.to_pandas(zero_copy_only=True)
    >>>Traceback (most recent call last):
      File ".../frame.py", line 105, in <module>
        frame.to_pandas(zero_copy_only=True)
      File ".../lib/python3.10/site-packages/polars/dataframe/frame.py", line 2223, in to_pandas
        return self._to_pandas_without_object_columns(
      File ".../lib/python3.10/site-packages/polars/dataframe/frame.py", line 2285, in _to_pandas_without_object_columns
        return tbl.to_pandas(date_as_object=date_as_object, **kwargs)
      File "pyarrow/array.pxi", line 872, in pyarrow.lib._PandasConvertible.to_pandas
      File "pyarrow/table.pxi", line 4904, in pyarrow.lib.Table._to_pandas
      File ".../lib/python3.10/site-packages/pyarrow/pandas_compat.py", line 779, in table_to_dataframe
        result = pa.lib.table_to_blocks(options, table, categories,
      File "pyarrow/table.pxi", line 3771, in pyarrow.lib.table_to_blocks
      File "pyarrow/error.pxi", line 91, in pyarrow.lib.check_status
    pyarrow.lib.ArrowInvalid: Cannot do zero copy conversion into multi-column DataFrame block
  3. yudhiesh commented on May 2, 2025

    @yudhiesh

    Still running into this issue on v18.0.0

  4. gwerbin-tive commented on Sep 15, 2025

    @gwerbin-tive

    I still have this problem with Pyarrow 21.0.0 and Pandas 2.3.2:

    # /// script
    # dependencies = ['pyarrow == 21.0.0', 'pandas == 2.3.2']
    # ///
    
    import sys
    import pyarrow
    
    tb = pyarrow.table({'a': [1.0, 2.0, 3.0]})
    try:
        df = tb.to_pandas(zero_copy_only=True)
    except pyarrow.ArrowInvalid as e:
        print(f"Error!: {e}")
    else:
        print("No error :)")

    Reproduce with UV under uv run, tested with UV 0.8.17.

  5. tigerlee commented on Oct 17, 2025

    @tigerlee

    Works with tb.to_pandas(zero_copy_only=True, split_blocks=True, types_mapper=pd.ArrowDtype)

  6. added
    Status: confirmed
    on Nov 19, 2026
  7. sameer727 commented on Nov 22, 2026

    @sameer727

    Root cause and fix: in the consolidated-block path (split_blocks=False), allow_zero_copy_blocks is never enabled in arrow_to_pandas.cc, so zero_copy_only=True always raises for Table/RecordBatch conversions, even for a single column. When zero_copy_only=True is requested, the columns can be converted as separate pandas blocks (per-column blocks can reference the original Arrow memory); conversions that genuinely need to copy still raise ArrowInvalid. Opened a PR: #55727 — verified locally with pyarrow 24.0.0 + pandas 3.0.2, regression tests included.

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