pola-rs/polars · error · ValueError

`n_rows` cannot be used with `use_pyarrow=True` and…

Error message

`n_rows` cannot be used with `use_pyarrow=True` and `memory_map=False`

What it means

When `use_pyarrow=True`, read_ipc delegates to pyarrow's IPC reader, which (with memory_map=False) cannot limit the number of rows it reads. Polars therefore rejects `n_rows` combined with use_pyarrow=True upfront with this ValueError.

Solutions

  1. Drop `use_pyarrow=True` so polars' native reader (which supports n_rows) is used
  2. Drop `n_rows` and slice afterwards: `pl.from_arrow(pa.ipc.open_file(...).read_all()).head(n)` — or `.head(n)` on the returned frame
  3. Enable memory_map=True with use_pyarrow if the file is local and mmap is acceptable (check whether that path supports n_rows in your polars version)
  4. Read with pyarrow directly and convert: `pl.from_arrow(pa.ipc.open_file(src).read_nrows(n))`

Example fix

// before
df = pl.read_ipc('data.arrow', n_rows=100, use_pyarrow=True)  # ValueError
// after
df = pl.read_ipc('data.arrow', n_rows=100)  # native reader
# or, with pyarrow:
import pyarrow.ipc as ipc
df = pl.from_arrow(ipc.open_file('data.arrow').read_all()).head(100)
Defensive patterns

Strategy: validation

Validate before calling

if use_pyarrow and n_rows:
    raise ValueError('n_rows is unsupported with use_pyarrow=True; drop one')

Try / catch

try:
    df = pl.read_ipc(path, n_rows=n, use_pyarrow=True)
except ValueError as e:
    if 'n_rows' in str(e):
        df = pl.read_ipc(path, n_rows=n)  # native reader

Prevention

When it happens

Trigger: Calling `pl.read_ipc(path, n_rows=1000, use_pyarrow=True)` (memory_map defaults to False).

Common situations: Porting code from polars-native IPC reading (which supports n_rows) to the pyarrow backend; adding use_pyarrow=True for compat with older polars behavior while keeping n_rows limits; reading feather/arrow files with row caps.

Understand the failure class

Background: Conflicting config options: "cannot be used together" — configuration validation errors across open-source libraries — this error's family across 162 libraries.

Related errors


AI-assisted analysis of pola-rs/polars@fe841f959e (2026-09-18). Data as JSON: /api/errors/02519255ea4c52da. Report an issue: GitHub.

Appendix: source

Thrown at py-polars/src/polars/io/ipc/functions.py:137

        - Arrow data in the file is not validated to be correct and invalid arrow
          data is UB! Ensure this file is correct or set `memory_map=False`.
        - You cannot write to the same filename.
          E.g. `pl.read_ipc("my_file.arrow").write_ipc("my_file.arrow")`
          will fail.
    """
    projection, column_names = parse_columns_arg(columns)
    del columns
    row_index = parse_row_index_args(row_index_name, row_index_offset)
    del row_index_name
    del row_index_offset

    if use_pyarrow:
        if n_rows:
            msg = (
                "`n_rows` cannot be used with `use_pyarrow=True` and `memory_map=False`"
            )
            raise ValueError(msg)

        if (isinstance(v := source, (str, Path))) and str(v).startswith("hf://"):
            msg = "`use_pyarrow=True` is not supported for Hugging Face"
            raise ValueError(msg)

        with prepare_file_arg(
            source, use_pyarrow=use_pyarrow, storage_options=storage_options
        ) as data:
            pyarrow_ipc = import_optional(
                "pyarrow.ipc",
                err_prefix="",
                err_suffix="is required when using 'read_ipc(..., use_pyarrow=True)'",
            )

            if column_names is not None:
                initial_pos: Any = None

                if hasattr(data, "tell") and callable(data.tell):

View on GitHub (pinned to fe841f959e)