NVIDIA / NVIDIA/cudf

read_csv throws when skiprows passes the end of the file while nrows is set

Open Beginner friendly
#23,802 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
C++
Stars
9.8k
Forks
1.1k
Avg merge
3d 6m
Merged PRs (30d)
278

Description

### Describe the problem
`read_csv` throws when `skiprows` skips past the end of the file and `nrows` is set, instead of returning an empty result.

Reproduction against libcudf 26.10 nightly (CUDA 12.9, sm_120), reading the two-row buffer `"a,b\n1,2\n3,4\n"` from memory:

```
skiprows=5, nrows=10 -> cudf::logic_error: "New size must be smaller"
at cpp/src/io/csv/reader_impl.cu:97
```

Root cause: in `select_data_and_row_offsets`, the num_rows clamp tests `static_cast(num_rows) < row_offsets.size() - 1`. When every row is discarded by skiprows, `row_offsets` is empty and `row_offsets.size() - 1` underflows to SIZE_MAX, so the clamp always fires and `shrink(num_rows + 1)` fails its `CUDF_EXPECTS`. The subtraction predates the `device_uvector` refactor (#7805); before that the clamp was a resize with an underflow-proof min.

Empty input is not an error elsewhere in libcudf (empty file reads return an empty table), so this combination should also return an empty table.

### Steps to reproduce
1. Build a two-row CSV buffer as above.
2. Call read_csv with skiprows=5 (greater than the row count) and nrows=10.
3. Observe the logic_error instead of an empty table.

Contributor guide

Open the contributing guide

Research direction

Start in cpp/src/io/csv/reader_impl.cu at select_data_and_row_offsets, especially the num_rows clamp near line 97. Reproduce the two-row buffer with skiprows=5 and nrows=10, then add or run the relevant CSV reader regression coverage. Done means the call returns an empty table without throwing a logic_error.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
data
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Active
Clarity
Clearly specified
Newbie friendliness
78/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.