Skip to content

GH-53290: [Python] CSV: expose pad_short_rows parse option in Python - #54691

Open
Mr-Nobody-Anonymous wants to merge 2 commits into
apache:mainfrom
Mr-Nobody-Anonymous:gh-53290-csv-pad-short-rows
Open

Mr-Nobody-Anonymous wants to merge 2 commits into
apache:mainfrom
Mr-Nobody-Anonymous:gh-53290-csv-pad-short-rows

Conversation

@Mr-Nobody-Anonymous

@Mr-Nobody-Anonymous Mr-Nobody-Anonymous commented Oct 20, 2026 •

Copy link
Copy Markdown

Rationale for this change

In #50926, pad_short_rows was implemented in the C++ CSV parser/reader (�rrow::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?

  • Expose pad_short_rows on CCSVParseOptions in python/pyarrow/includes/libarrow.pxd.
  • Add pad_short_rows parameter to pyarrow.csv.ParseOptions.init, defaulting to None (preserving C++ default alse).
  • Add pad_short_rows property (getter and setter) on pyarrow.csv.ParseOptions.
  • Update ParseOptions.equals(), _repr_base(), getstate(), and backwards-compatible setstate().
  • Document ~ParseOptions.pad_short_rows in docs/source/python/csv.rst.
  • Add comprehensive unit tests in python/pyarrow/tests/test_csv.py:
    • Options validation, string/repr output, and serialization/pickling.
    • Backward compatibility when unpickling legacy 7-element ParseOptions state.
    • Equality differentiation when only pad_short_rows differs.
    • CSV table and streaming reading with pad_short_rows=True across serial and parallel readers for both numerical and string datasets.
    • Distinction between missing trailing fields (padded as nulls) and explicitly empty fields (preserved as empty strings).
    • Verification that excess columns still error when ignore_extra_columns=False.
    • Header-only CSV input verification.
    • Verification that default pad_short_rows=False retains strict error behavior.
    • Reading with explicit column names and typed schema conversions.
  • Add test coverage in python/pyarrow/tests/test_dataset.py for ds.CsvFileFormat(pa.csv.ParseOptions(pad_short_rows=True)) pickling and dataset reading via ds.dataset().

Are these changes tested?

Yes. Added tests in est_csv.py and est_dataset.py covering parse options validation, pickling, repr, legacy unpickling, and reading short rows in serial and parallel modes.

Are there any user-facing changes?

Yes. pyarrow.csv.ParseOptions now accepts pad_short_rows (defaulting to False), 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:

  • Human
  • AI

Reviewed before submission by:

  • Human
  • AI
  • Not reviewed

…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
Copilot AI balanced review requested due to automatic review settings October 20, 2026 10:52

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@github-actions

Copy link
Copy Markdown

⚠️ GitHub issue #53290 has been automatically assigned in GitHub to PR creator.

…_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)
Copilot AI balanced review requested due to automatic review settings October 20, 2026 11:35

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants