pola-rs/polars · error
invalid value for POLARS_CSV_CHUNK_PREFETCH_LIMIT
Error message
invalid value for POLARS_CSV_CHUNK_PREFETCH_LIMIT: {x} What it means
POLARS_CSV_CHUNK_PREFETCH_LIMIT caps how many CSV chunks may be prefetched concurrently during streaming CSV scans. If set and not parseable as a non-zero usize, Polars panics while building the CSV source (in set_execution_state).
Solutions
- Set a positive integer, e.g. export POLARS_CSV_CHUNK_PREFETCH_LIMIT=8.
- Unset it to default to num_pipelines * 2 (minimum 1).
- Grep shell init files and deployment manifests for the malformed value.
Example fix
# before export POLARS_CSV_CHUNK_PREFETCH_LIMIT=none # after export POLARS_CSV_CHUNK_PREFETCH_LIMIT=8
Defensive patterns
Strategy: validation
Validate before calling
import os
v = os.environ.get("POLARS_CSV_CHUNK_PREFETCH_LIMIT")
if v is not None:
assert v.isdigit() and int(v) > 0, f"POLARS_CSV_CHUNK_PREFETCH_LIMIT must be positive int, got {v!r}" Type guard
def is_positive_int(s: str) -> bool:
return s.isdigit() and int(s) > 0 Try / catch
v = os.environ.get("POLARS_CSV_CHUNK_PREFETCH_LIMIT", "")
if v and not (v.isdigit() and int(v) > 0):
os.environ.pop("POLARS_CSV_CHUNK_PREFETCH_LIMIT", None) # default: num_pipelines*2 Prevention
- Replace 'disable'/'none' placeholders with unset in CI matrices
- Keep the value >= 1; defaults already enforce a floor
- Audit shared tuning scripts for this var
- Validate POLARS_* env at job startup
When it happens
Trigger: Setting POLARS_CSV_CHUNK_PREFETCH_LIMIT to '0', 'none', '', or any non-positive-integer string, then scanning a CSV in the streaming engine (scan_csv/sink from CSV).
Common situations: Tuning IO concurrency for CSV ingestion; CI matrix env vars with a 'disable' placeholder value; unit-suffixed numbers.
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 `POLARS_PQ_PREFILTERED_MASK` value
- invalid value for POLARS_FORCE_CSV_INFER_READ_SIZE
- invalid value for POLARS_IDEAL_SINK_MORSEL_SIZE_BYTES
- invalid value for POLARS_IDEAL_SINK_MORSEL_SIZE_ROWS
- invalid value for POLARS_INFLIGHT_SINK_MORSEL_LIMIT
AI-assisted analysis of pola-rs/polars@fe841f959e (2026-09-18).
Data as JSON: /api/errors/c23b5807e88740d3.
Report an issue: GitHub.
Appendix: source
Thrown at crates/polars-stream/src/nodes/io_sources/csv/builder.rs:59
fn reader_capabilities(&self) -> ReaderCapabilities {
use ReaderCapabilities as RC;
if self.options.parse_options.comment_prefix.is_some() {
RC::empty()
} else {
RC::PRE_SLICE
}
}
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_CSV_CHUNK_PREFETCH_LIMIT")
.map(|x| {
x.parse::<NonZeroUsize>()
.ok()
.unwrap_or_else(|| {
panic!("invalid value for POLARS_CSV_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!(
"[CsvReaderBuilder]: 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)