You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@arrow.apache.org by "djouallah (via GitHub)" <gi...@apache.org> on 2026/10/12 02:43:33 UTC

[I] [C++][Python] CSV: option to pad short rows with nulls instead of failing [arrow]

djouallah opened a new issue, #53290:
URL: https://github.com/apache/arrow/issues/53290

   ### 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.
   
   ```python
   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 padded
   ```
   
   Expected, 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: https://github.com/pandas-dev/pandas/issues/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
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@arrow.apache.org.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] [C++][Python] CSV: option to pad short rows with nulls instead of failing [arrow]

Posted by "HuaHuaY (via GitHub)" <gi...@apache.org>.
HuaHuaY commented on issue #53290:
URL: https://github.com/apache/arrow/issues/53290#issuecomment-6139366118

   I believe the C++ part has already been implemented in #50926, but this configuration has not yet been exposed in Python.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] [C++][Python] CSV: option to pad short rows with nulls instead of failing [arrow]

Posted by "aryan9948 (via GitHub)" <gi...@apache.org>.
aryan9948 commented on issue #53290:
URL: https://github.com/apache/arrow/issues/53290#issuecomment-6130811414

   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?
   
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] [C++][Python] CSV: option to pad short rows with nulls instead of failing [arrow]

Posted by "aryan9948 (via GitHub)" <gi...@apache.org>.
aryan9948 commented on issue #53290:
URL: https://github.com/apache/arrow/issues/53290#issuecomment-6130802140

   Hi! I'd like to work on this issue. I'm investigating the existing `pad_short_rows` implementation and how it handles explicitly provided column names when the first CSV row is shorter than the expected width. Would it be okay for me to take this issue and work on a fix?
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] [C++][Python] CSV: option to pad short rows with nulls instead of failing [arrow]

Posted by "Mr-Nobody-Anonymous (via GitHub)" <gi...@apache.org>.
Mr-Nobody-Anonymous commented on issue #53290:
URL: https://github.com/apache/arrow/issues/53290#issuecomment-6289242422

   I have opened PR #54691 exposing `pad_short_rows` in `pyarrow.csv.ParseOptions` along with regression tests and docs.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] [C++][Python] CSV: option to pad short rows with nulls instead of failing [arrow]

Posted by "Mr-Nobody-Anonymous (via GitHub) via github" <gi...@arrow.apache.org>.
Mr-Nobody-Anonymous commented on issue #53290:
URL: https://github.com/apache/arrow/issues/53290#issuecomment-7009547539

   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.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org