Description
Describe the enhancement requested
Add an option to the CSV reader to read rows that have fewer fields than the number of columns, and fill the missing fields with null. pandas' C engine does this when names is given, and DuckDB has read_csv(..., null_padding = true).
Today the width is fixed by column_names, or by the first row. A shorter row is an error, and invalid_row_handler can only skip it or stop. It cannot keep the row.
import io
import pyarrow as pa
from pyarrow import csv
data = b"a,b\n1,2,3,4\n5,6,7,8\n"
names = ["w", "x", "y", "z"]
csv.read_csv(io.BytesIO(data), read_options=csv.ReadOptions(column_names=names))
# ArrowInvalid: CSV parse error: Expected 4 columns, got 2: a,b
csv.read_csv(io.BytesIO(data), read_options=csv.ReadOptions(autogenerate_column_names=True))
# ArrowInvalid: CSV parse error: Expected 2 columns, got 4: 1,2,3,4
csv.read_csv(io.BytesIO(data),
read_options=csv.ReadOptions(column_names=names),
parse_options=csv.ParseOptions(invalid_row_handler=lambda r: "skip"))
# {'w': [1, 5], 'x': [2, 6], 'y': [3, 7], 'z': [4, 8]} -- the short row is dropped, not paddedExpected, with the new option:
{'w': ['a', '1', '5'], 'x': ['b', '2', '6'], 'y': [None, '3', '7'], 'z': [None, '4', '8']}
Real files have this shape. For example, the AEMO (Australian electricity market) daily CSV files mix record types: the first row is a short header record, and the data rows are wider. pandas with engine="pyarrow" cannot read them, because pandas uses Arrow's reader and Arrow takes the width from the first row. pandas marked this as an Arrow limitation: pandas-dev/pandas#71034
The same request was #27832, closed as stale in January 2026. #28421 added invalid_row_handler, but it can only skip or error.
Tested with pyarrow 26.0.0, Python 3.12, Linux.
Component(s)
C++, Python
Activity
aryan9948 commentedon Oct 12, 2026
Hi, I'd like to contribute a fix for this issue. I'm investigating how the CSV reader determines the column count and handles rows with fewer fields than expected. I'd be happy to work on the C++ implementation and Python API if no one is already working on it. Would it be okay for me to take this issue?
HuaHuaY commentedon Oct 13, 2026
I believe the C++ part has already been implemented in #50926, but this option has not yet been exposed in Python.
Mr-Nobody-Anonymous commentedon Oct 20, 2026
I have opened PR #54691 exposing
pad_short_rowsinpyarrow.csv.ParseOptionsalong with regression tests and docs.apacheGH-53290: [Python] Fix test assertions and expand CSV pad_short…
apacheGH-53290: [Python] Move dataset creation inside pytest.raises c…
Mr-Nobody-Anonymous commentedon Nov 19, 2026
Update: The review feedback on PR #54691 has been addressed (commit b75d874) — the dataset test exception handling was fixed and the PR description formatting cleaned up. All CI test suites across Linux, macOS, and Windows (Python 3.11–3.14) are now passing.
apacheGH-53290: [Python] Simplify ParseOptions.__setstate__ without l…
apacheGH-53290: [Python] Add short first row test case with column_na…
apacheGH-53290: [Python] Remove unreachable to_table call in test_csv…
apacheGH-53290: [Python] Trim pad_short_rows tests to plumbing per re…