pola-rs/polars · error
invalid value for POLARS_RECORD_BATCH_PREFETCH_KBYTES_BUDGET
Error message
invalid value for POLARS_RECORD_BATCH_PREFETCH_KBYTES_BUDGET: {x} What it means
Polars panics when POLARS_RECORD_BATCH_PREFETCH_KBYTES_BUDGET is set but cannot be parsed as a non-zero usize. The IPC source builder reads it in set_execution_state as a byte-budget (in KiB) for prefetched batches; unset falls back to a budget computed from FetchConfig's target chunk size.
Solutions
- Set the variable to a bare positive integer number of KiB, e.g. 262144.
- Unset the variable to use the default budget derived from FetchConfig::random_access().chunk_size.
- Strip any unit suffixes or whitespace from the value before export.
Example fix
// before POLARS_RECORD_BATCH_PREFETCH_KBYTES_BUDGET=256MB // after POLARS_RECORD_BATCH_PREFETCH_KBYTES_BUDGET=262144
Defensive patterns
Strategy: validation
Validate before calling
const v = process.env.POLARS_RECORD_BATCH_PREFETCH_KBYTES_BUDGET;
if (v !== undefined && (!/^\d+$/.test(v.trim()) || parseInt(v, 10) === 0)) {
throw new Error(`POLARS_RECORD_BATCH_PREFETCH_KBYTES_BUDGET must be a positive integer (KiB), got: '${v}'`);
} Type guard
function isValidKbytesBudget(v) { return v === undefined || (/^\d+$/.test(v.trim()) && Number(v.trim()) > 0); } Try / catch
try {
runIpcScan();
} catch (e) {
if (String(e).includes('PREFETCH_KBYTES_BUDGET')) {
delete process.env.POLARS_RECORD_BATCH_PREFETCH_KBYTES_BUDGET;
runIpcScan();
} else throw e;
} Prevention
- Remember the unit is KiB — never append KB/MB suffixes.
- Compute MB -> KiB in your deployment tooling, not by hand in env files.
- Centralize Polars tuning env vars in one validated config module.
When it happens
Trigger: Starting a streaming IPC scan with the variable set to a non-numeric, zero, negative, or out-of-range string (e.g. '10MB', '', '0').
Common situations: Operators copy a memory budget like '262144KB' or '256MB' from tuning notes; the 'KB'/'MB' suffix and empty values are the usual culprits.
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_RECORD_BATCH_PREFETCH_SIZE
- invalid value for POLARS_CSV_CHUNK_SIZE
- invalid value for POLARS_FORCE_NDJSON_READ_SIZE
- invalid value for POLARS_LINES_CHUNK_PREFETCH_LIMIT
- invalid value for POLARS_MAX_CONCURRENT_SCANS
AI-assisted analysis of pola-rs/polars@fe841f959e (2026-09-18).
Data as JSON: /api/errors/311c941aca908cce.
Report an issue: GitHub.
Appendix: source
Thrown at crates/polars-stream/src/nodes/io_sources/ipc/builder.rs:75
panic!("invalid value for POLARS_RECORD_BATCH_PREFETCH_SIZE: {x}")
})
.get()
})
.unwrap_or(
// Similar to Parquet.
execution_state
.num_pipelines
.saturating_mul(2)
.max(get_request_budget() as usize)
.clamp(16, 2048),
)
.max(1);
let prefetch_kbytes_limit = std::env::var("POLARS_RECORD_BATCH_PREFETCH_KBYTES_BUDGET")
.map(|x| {
x.parse::<NonZeroUsize>()
.unwrap_or_else(|_| {
panic!("invalid value for POLARS_RECORD_BATCH_PREFETCH_KBYTES_BUDGET: {x}")
})
.get()
})
.unwrap_or({
// Similar to Parquet.
let target_chunk_size_kb = FetchConfig::random_access().chunk_size.div_ceil(1024);
4 * execution_state.num_pipelines * target_chunk_size_kb
})
// Avoid deadlock.
.max(polars_io::cloud::concurrency_config::get_download_chunk_size().div_ceil(1024));
if config::verbose() {
eprintln!(
"[IpcReaderBuilder]: prefetch_limit: {}, prefetch_kbytes_limit: {}",
prefetch_limit, prefetch_kbytes_limit
);
}
View on GitHub (pinned to fe841f959e)