{"record":{"id":"02519255ea4c52da","repo":"pola-rs/polars","slug":"n-rows-cannot-be-used-with-use-pyarrow-true-an","errorCode":null,"errorMessage":"`n_rows` cannot be used with `use_pyarrow=True` and `memory_map=False`","messagePattern":"`n_rows` cannot be used with `use_pyarrow=True` and `memory_map=False`","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"py-polars/src/polars/io/ipc/functions.py","lineNumber":137,"sourceCode":"\n        - Arrow data in the file is not validated to be correct and invalid arrow\n          data is UB! Ensure this file is correct or set `memory_map=False`.\n        - You cannot write to the same filename.\n          E.g. `pl.read_ipc(\"my_file.arrow\").write_ipc(\"my_file.arrow\")`\n          will fail.\n    \"\"\"\n    projection, column_names = parse_columns_arg(columns)\n    del columns\n    row_index = parse_row_index_args(row_index_name, row_index_offset)\n    del row_index_name\n    del row_index_offset\n\n    if use_pyarrow:\n        if n_rows:\n            msg = (\n                \"`n_rows` cannot be used with `use_pyarrow=True` and `memory_map=False`\"\n            )\n            raise ValueError(msg)\n\n        if (isinstance(v := source, (str, Path))) and str(v).startswith(\"hf://\"):\n            msg = \"`use_pyarrow=True` is not supported for Hugging Face\"\n            raise ValueError(msg)\n\n        with prepare_file_arg(\n            source, use_pyarrow=use_pyarrow, storage_options=storage_options\n        ) as data:\n            pyarrow_ipc = import_optional(\n                \"pyarrow.ipc\",\n                err_prefix=\"\",\n                err_suffix=\"is required when using 'read_ipc(..., use_pyarrow=True)'\",\n            )\n\n            if column_names is not None:\n                initial_pos: Any = None\n\n                if hasattr(data, \"tell\") and callable(data.tell):","sourceCodeStart":119,"sourceCodeEnd":155,"githubUrl":"https://github.com/pola-rs/polars/blob/fe841f959ef4d2ceefc05a310d33ed7b1ab24e5e/py-polars/src/polars/io/ipc/functions.py#L119-L155","documentation":"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.","triggerScenarios":"Calling `pl.read_ipc(path, n_rows=1000, use_pyarrow=True)` (memory_map defaults to False).","commonSituations":"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.","solutions":["Drop `use_pyarrow=True` so polars' native reader (which supports n_rows) is used","Drop `n_rows` and slice afterwards: `pl.from_arrow(pa.ipc.open_file(...).read_all()).head(n)` — or `.head(n)` on the returned frame","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)","Read with pyarrow directly and convert: `pl.from_arrow(pa.ipc.open_file(src).read_nrows(n))`"],"exampleFix":"// before\ndf = pl.read_ipc('data.arrow', n_rows=100, use_pyarrow=True)  # ValueError\n// after\ndf = pl.read_ipc('data.arrow', n_rows=100)  # native reader\n# or, with pyarrow:\nimport pyarrow.ipc as ipc\ndf = pl.from_arrow(ipc.open_file('data.arrow').read_all()).head(100)","handlingStrategy":"validation","validationCode":"if use_pyarrow and n_rows:\n    raise ValueError('n_rows is unsupported with use_pyarrow=True; drop one')","typeGuard":null,"tryCatchPattern":"try:\n    df = pl.read_ipc(path, n_rows=n, use_pyarrow=True)\nexcept ValueError as e:\n    if 'n_rows' in str(e):\n        df = pl.read_ipc(path, n_rows=n)  # native reader","preventionTips":["Don't combine n_rows with use_pyarrow=True","Slice after load when using the pyarrow backend","Prefer polars' native IPC reader unless pyarrow-specific behavior is required","Check memory_map implications when switching backends"],"tags":["ipc","arrow","pyarrow","n-rows"],"backgroundTag":"conflicting-config-options","analyzedSha":"fe841f959ef4d2ceefc05a310d33ed7b1ab24e5e","analyzedAt":"2026-09-18T22:14:11.667Z","contentChangedAt":"2026-09-18T22:14:11.667Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}