pola-rs/polars · error
invalid value for POLARS_NDJSON_CHUNK_PREFETCH_LIMIT
Error message
invalid value for POLARS_NDJSON_CHUNK_PREFETCH_LIMIT: {x} What it means
Polars panics when POLARS_NDJSON_CHUNK_PREFETCH_LIMIT is set but cannot be parsed as a non-zero usize. The NDJSON source builder reads it in set_execution_state to cap concurrently prefetched chunks; the default is 2x num_pipelines, clamped to at least 1.
Solutions
- Set the variable to a plain positive integer (e.g. 4).
- Unset the variable to use the default 2*num_pipelines limit.
- Grep shell profiles and container configs for stale/invalid values of this variable.
Example fix
// before POLARS_NDJSON_CHUNK_PREFETCH_LIMIT=auto // after POLARS_NDJSON_CHUNK_PREFETCH_LIMIT=4 # or unset
Defensive patterns
Strategy: validation
Validate before calling
const v = process.env.POLARS_NDJSON_CHUNK_PREFETCH_LIMIT;
if (v !== undefined && (!/^\d+$/.test(v.trim()) || parseInt(v, 10) === 0)) {
throw new Error(`POLARS_NDJSON_CHUNK_PREFETCH_LIMIT must be a positive integer, got: '${v}'`);
} Type guard
function isValidNdjsonPrefetch(v) { return v === undefined || (/^\d+$/.test(v.trim()) && Number(v.trim()) > 0); } Try / catch
try {
runNdjsonScan();
} catch (e) {
if (String(e).includes('POLARS_NDJSON_CHUNK_PREFETCH_LIMIT')) {
delete process.env.POLARS_NDJSON_CHUNK_PREFETCH_LIMIT;
runNdjsonScan();
} else throw e;
} Prevention
- Don't attempt to 'disable' prefetch with 0 — unset instead.
- Keep numeric tuning env vars consistent across environments.
- Run a smoke scan in CI with the same env vars as production.
When it happens
Trigger: Streaming scan_ndjson with the variable set to '', '0', 'auto', or a value exceeding usize range.
Common situations: Users copy env settings between Polars versions or set '0' attempting to disable prefetch, both of which fail the NonZeroUsize parse.
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
- invalid value for POLARS_FORCE_NDJSON_READ_SIZE
- invalid value for POLARS_CSV_CHUNK_SIZE
- invalid value for POLARS_LINES_CHUNK_PREFETCH_LIMIT
- invalid value for POLARS_MAX_CONCURRENT_SCANS
- invalid value for POLARS_NUM_READERS_PRE_INIT
AI-assisted analysis of pola-rs/polars@fe841f959e (2026-09-18).
Data as JSON: /api/errors/7f26c5f6d65ae0f4.
Report an issue: GitHub.
Appendix: source
Thrown at crates/polars-stream/src/nodes/io_sources/ndjson/builder.rs:59
#[cfg(feature = "json")]
impl FileReaderBuilder for NDJsonReaderBuilder {
fn reader_name(&self) -> &str {
"ndjson"
}
fn reader_capabilities(&self) -> ReaderCapabilities {
ndjson_reader_capabilities()
}
fn set_execution_state(&self, execution_state: &crate::execute::StreamingExecutionState) {
// The maximum number of chunks actively being prefetched at any given point in time.
let prefetch_limit = std::env::var("POLARS_NDJSON_CHUNK_PREFETCH_LIMIT")
.map(|x| {
x.parse::<NonZeroUsize>()
.ok()
.unwrap_or_else(|| {
panic!("invalid value for POLARS_NDJSON_CHUNK_PREFETCH_LIMIT: {x}")
})
.get()
})
.unwrap_or(execution_state.num_pipelines.saturating_mul(2))
.max(1);
self.prefetch_limit.store(prefetch_limit);
if config::verbose() {
eprintln!(
"[NDJsonReaderBuilder]: prefetch_limit: {}",
self.prefetch_limit.load()
);
}
self.prefetch_semaphore
.set(Arc::new(tokio::sync::Semaphore::new(prefetch_limit)))
.unwrap()View on GitHub (pinned to fe841f959e)