pola-rs/polars · error · ValueError

cannot return a zero-copy array

Error message

cannot return a zero-copy array

What it means

Series.to_pandas documents that data is copied unless use_pyarrow_extension_array=True; when zero-copy is requested but impossible for this series (e.g. a dtype with no matching PyArrow-backed extension array or arrow-backed representation), the code raises this error because it cannot hand out the buffer without copying.

Source

Thrown at py-polars/src/polars/series/series.py:5053

    ) -> pd.Series[Any]:
        """
        Convert this Series to a pandas Series.

        This operation copies data if `use_pyarrow_extension_array` is not enabled.

        Parameters
        ----------
        use_pyarrow_extension_array
            Use a PyArrow-backed extension array instead of a NumPy array for the pandas
            Series. This allows zero copy operations and preservation of null values.
            Subsequent operations on the resulting pandas Series may trigger conversion
            to NumPy if those operations are not supported by PyArrow compute functions.
        **kwargs
            Additional keyword arguments to be passed to
            :meth:`pyarrow.Array.to_pandas`.

        Returns
        -------
        :class:`pandas.Series`

        Notes
        -----
        This operation requires that both :mod:`pandas` and :mod:`pyarrow` are
        installed.

        Examples
        --------
        >>> s = pl.Series("a", [1, 2, 3])
        >>> s.to_pandas()
        0    1
        1    2
        2    3
        Name: a, dtype: int64

        Null values are converted to `NaN`.

View on GitHub (pinned to 68506541d2)

Solutions

  1. Allow a copy instead of requiring zero-copy, e.g. call `to_numpy()` without `zero_copy_only=True`, or ensure the Series is contiguous and of a compatible dtype.
Defensive patterns

Strategy: fallback

When it happens

Trigger: Thrown at py-polars/src/polars/series/series.py:5044 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of pola-rs/polars@68506541d2 (2026-08-19). Data as JSON: /api/errors/7105bc27bfabc665. Report an issue: GitHub.