Repository navigation
GH-53290: [Python] CSV: expose pad_short_rows parse option in Python - #54691
Conversation
…ython Add pad_short_rows to pyarrow.csv.ParseOptions, allowing short CSV rows with fewer fields than expected to be padded with null values rather than raising an ArrowInvalid parse error. * Add pad_short_rows property, init argument, equals, repr, and serialization in _csv.pyx * Expose pad_short_rows in libarrow.pxd CCSVParseOptions * Add tests in test_csv.py and test_dataset.py * Document option in docs/source/python/csv.rst
|
|
…_rows test coverage * Correct integer type expectation for numerical short row CSV tests * Add string data test cases for pad_short_rows * Test distinction between missing trailing fields and empty fields * Test error on excess columns when pad_short_rows=True * Test header-only input with pad_short_rows=True * Test backward-compatible unpickling of legacy 7-element ParseOptions state * Test ParseOptions equality differentiation on pad_short_rows * Add dataset reader integration test with CsvFileFormat(pad_short_rows=True)
|
There are some invisible characters in the PR description. Could you please fix them? Also, before submitting a PR, you should take the time to read https://arrow.apache.org/docs/dev/developers/overview.html#ai-generated-code. |
…ontext in test_csv_format_pad_short_rows
|
Thank you for the review! I have cleaned up the PR description to remove all unescaped control characters, reviewed the AI generation guidelines in the developer documentation, and fixed the failing test assertion in |
…egacy tuple handling
…mes in test_csv.py
…_format_pad_short_rows
|
@pearu could you do a quick pass here? |
pearu
left a comment
There was a problem hiding this comment.
The binding change looks good to me. I'd ask for the tests to be trimmed to the plumbing, since most of the new cases re-test C++ behaviour that already has C++ tests.
Once the tests are trimmed, the test list under "What changes are included" and "Are these changes tested?" needs updating to match.
|
Thanks for the review @pearu ! |
pearu
left a comment
There was a problem hiding this comment.
LGTM, thanks @Mr-Nobody-Anonymous!
|
Will merge when CI is green. |
|
Thanks for the PR @Mr-Nobody-Anonymous and thanks for the review @pearu ! |

Rationale for this change
In #50926,
pad_short_rowswas implemented in the C++ CSV parser/reader (arrow::csv::ParseOptions::pad_short_rows), allowing rows with fewer fields than expected to be padded with null values rather than failing. However, this option was not yet exposed to the Python bindings (#53290).What changes are included in this PR?
pad_short_rowsonCCSVParseOptionsinpython/pyarrow/includes/libarrow.pxd.pad_short_rowsparameter topyarrow.csv.ParseOptions.__init__, defaulting toNone(preserving C++ defaultfalse).pad_short_rowsproperty (getter and setter) onpyarrow.csv.ParseOptions.ParseOptions.equals(),_repr_base(),__getstate__(), and__setstate__().ParseOptions.pad_short_rowsindocs/source/python/csv.rst.python/pyarrow/tests/test_csv.py:test_parse_options: option validation, equality, repr/str output, and serialization/pickling withpad_short_rows.test_pad_short_rows: reading short rows withParseOptions(pad_short_rows=True)and explicit column names.python/pyarrow/tests/test_dataset.py:test_file_format_pickling: picklingds.CsvFileFormat(pa.csv.ParseOptions(pad_short_rows=True)).test_csv_format_pad_short_rows: reading short CSV rows viads.dataset()withpad_short_rows=True.Are these changes tested?
Yes. Updated
test_csv.py(test_parse_options,test_pad_short_rows) andtest_dataset.py(test_file_format_pickling,test_csv_format_pad_short_rows) to test option plumbing, pickling, CSV reading, and dataset reading.Are there any user-facing changes?
Yes.
pyarrow.csv.ParseOptionsnow acceptspad_short_rows(defaulting toFalse), allowing users to opt into padding short rows with nulls.Was AI used for this PR?
AI assistance was used for code drafting, technical audit, and test authoring. The architecture, C++ mapping, test cases, and documentation were reviewed and verified.
PR code and description written by:
Reviewed before submission by: