pola-rs/polars · error
invalid value for POLARS_NDJSON_CHUNK_SIZE
Error message
invalid value for POLARS_NDJSON_CHUNK_SIZE: {x} What it means
Polars panics when the POLARS_NDJSON_CHUNK_SIZE environment variable is set but cannot be parsed as a non-zero usize. This variable controls the chunk size (in bytes) used when reading newline-delimited JSON files in the streaming engine; it defaults to 32 MiB. The panic happens in begin_read when parsing the user-provided value fails or the value is zero.
Solutions
- Unset POLARS_NDJSON_CHUNK_SIZE to fall back to the 32 MiB default
- Set it to a plain positive decimal integer without units or spaces, e.g. export POLARS_NDJSON_CHUNK_SIZE=33554432
- Ensure the value is non-zero and fits in a usize (max 2^64-1 on 64-bit platforms)
Example fix
// before export POLARS_NDJSON_CHUNK_SIZE=32mb // after export POLARS_NDJSON_CHUNK_SIZE=33554432
Defensive patterns
Strategy: validation
Validate before calling
// Rust: validate before launching
if let Ok(v) = std::env::var("POLARS_NDJSON_CHUNK_SIZE") {
assert!(v.parse::<NonZeroUsize>().is_ok(), "POLARS_NDJSON_CHUNK_SIZE must be a positive integer, got: {v}");
} Type guard
fn valid_chunk_size(v: &str) -> bool { v.parse::<NonZeroUsize>().is_ok() } Prevention
- Never include unit suffixes or spaces in POLARS_* numeric env vars
- Validate env config in CI before running Polars jobs
- Prefer leaving the variable unset unless tuning is required
When it happens
Trigger: Setting POLARS_NDJSON_CHUNK_SIZE to a non-numeric string (e.g. '32mb'), a negative number, a zero value ('0'), or an integer larger than usize::MAX, then starting an NDJSON scan with scan_nd_json / pl.scan_ndjson in the streaming engine.
Common situations: Users copy tuning advice and include units like '32M' or '33554432b', set the value in a shell profile with quotes/whitespace, or set it to 0 thinking it means 'unlimited'. Non-ASCII or invisible characters (BOM, trailing newline in dotenv files) also break parsing.
Understand the failure class
Background: "is not a valid" / "Invalid ... value" environment variable errors: how libraries validate env vars and what to do when they reject yours — this error's family across 48 libraries.
Related errors
- could not parse table width argument
- creating extension types not allowed - try setting the…
- integer
- Invalid `POLARS_PQ_PREFILTERED_MASK` value
- invalid value for
AI-assisted analysis of pola-rs/polars@fe841f959e (2026-09-18).
Data as JSON: /api/errors/3133c2f66de2d902.
Report an issue: GitHub.
Appendix: source
Thrown at crates/polars-stream/src/nodes/io_sources/ndjson/mod.rs:430
let row_skipper = RowSkipper {
cfg_n_rows_to_skip: n_rows_to_skip,
n_rows_skipped: 0,
is_line: self.chunk_reader_builder.is_line_fn(),
reverse: is_negative_slice,
};
// Unify the two source options (uncompressed local file mmapp'ed, or streaming async with
// transparent decompression), into one unified reader source.
let reader_source = if use_async_prefetch {
// Prepare parameters for Prefetch task.
// TODO REFACTOR: use get_streaming_chunk_size()
const DEFAULT_NDJSON_CHUNK_SIZE: usize = 32 * 1024 * 1024;
let memory_prefetch_func = get_memory_prefetch_func(verbose);
let chunk_size = std::env::var("POLARS_NDJSON_CHUNK_SIZE")
.map(|x| {
x.parse::<NonZeroUsize>()
.unwrap_or_else(|_| {
panic!("invalid value for POLARS_NDJSON_CHUNK_SIZE: {x}")
})
.get()
})
.unwrap_or(DEFAULT_NDJSON_CHUNK_SIZE);
let prefetch_limit = self
.chunk_prefetch_sync
.prefetch_limit
.min(file_size.div_ceil(chunk_size))
.max(1);
let (prefetch_send, prefetch_recv) = tokio::sync::mpsc::channel(prefetch_limit);
// Task: Prefetch.
// Initiate parallel downloads of raw data chunks.
let byte_source = byte_source.clone();
let prefetch_task = {
let prefetch_semaphore = Arc::clone(&self.chunk_prefetch_sync.prefetch_semaphore);View on GitHub (pinned to fe841f959e)