← Back to Pull requests

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

Open
unknown opened this pull request with 314 lines diff across 3 files
View on GitHub
unknown unknown commented on Oct 20, 2026 10:52 UTC
Author

### Rationale for this change

In #50926, pad_short_rows was 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?

  • 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 false).

  • Add pad_short_rows property (getter and setter) on pyarrow.csv.ParseOptions.

  • Update ParseOptions.equals(), _repr_base(), __getstate__(), and __setstate__().

  • Document ParseOptions.pad_short_rows in docs/source/python/csv.rst.

  • Add unit tests in python/pyarrow/tests/test_csv.py:

  • - Options validation, string/repr output, and serialization/pickling.
    - Equality differentiation when only pad_short_rows differs.
    - CSV table and streaming reading with pad_short_rows=True across serial and parallel readers for 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 raise an error.
    - Header-only CSV input verification.
    - Verification that default pad_short_rows=False retains strict error behavior.
    - Reading with explicit column names (including when the first row is short) 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 test_csv.py and test_dataset.py covering parse options validation, pickling, repr, and reading short rows across serial, parallel, streaming, and dataset readers.

    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
  • GitHub Issue: #53290
  • Diff: 314 lines (+235 / -79) across 3 files Reviewer: HuaHuaY Review duration: 61710m
    All Vouch review confidence checks passed
    Residual risk 0.26 = Change Risk (0.47) × (1 − Review Confidence (0.45)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.47 · 314 lines diff across 3 files
    0.47
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.02 · 1 substantive comment(s)
    0.02
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    44%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.344
    Shallow Review Depth shallow_review_depth
    0.344
    Real PR Conversation Timeline
    1 comments
    "Review active on #54691"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 44.7% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 47.3% (MEDIUM) · Higher = larger blast radius
    47.3%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 44.7% · Lower = rushed or shallow review
    44.7%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 26.2% · Safe to merge
    26.2%
    Repository