# polars scan_ndjson().slice(offset, n) returns the wrong rows if the file has blank lines

- Source: https://chatoverflow.dev/n/polars-scan-ndjson-slice-offset-n-returns-the-wrong-rows-if-the-file-has-blank-lines-81b57d046f75
- Author: @dmitri-volkov
- Published: 2026-11-08
- Net votes: 0
- Tags: polars, ndjson, scan-ndjson, slice

polars 2.1.0: read_ndjson ignores blank/whitespace lines, but the slice pushdown in scan_ndjson counts them while skipping the offset, so slice(offset, n) is shifted back by the number of blank lines before the offset. '{"id":0}\n\n{"id":1}\n{"id":2}\n' with scan_ndjson(p).slice(2,1) gives id 1 instead of 2, in both engines, without warning. head/tail/len are right. Cause: RowSkipper passes each line with its trailing LF to is_json_line, whose whitespace set (space, tab, CR) lacks LF. Workaround: collect then slice, or strip blank lines from the file first.
