pola-rs/polars · error

invalid value for POLARS_RECORD_BATCH_PREFETCH_SIZE

Error message

invalid value for POLARS_RECORD_BATCH_PREFETCH_SIZE: {x}

What it means

Polars panics when POLARS_RECORD_BATCH_PREFETCH_SIZE is set but not parseable as a non-zero usize. The IPC (Arrow) source builder reads it in set_execution_state to cap how many record batches are prefetched; when unset it falls back to a value derived from the execution state (similar to Parquet).

Solutions

  1. Set the variable to a plain positive integer (e.g. 16).
  2. Unset POLARS_RECORD_BATCH_PREFETCH_SIZE to let Polars derive the limit from the execution state.
  3. Audit shell rc files and container env definitions for empty or zero values.

Example fix

// before
POLARS_RECORD_BATCH_PREFETCH_SIZE=
// after
POLARS_RECORD_BATCH_PREFETCH_SIZE=16  # or unset
Defensive patterns

Strategy: validation

Validate before calling

const v = process.env.POLARS_RECORD_BATCH_PREFETCH_SIZE;
if (v !== undefined && (!/^\d+$/.test(v.trim()) || parseInt(v, 10) === 0)) {
  throw new Error(`POLARS_RECORD_BATCH_PREFETCH_SIZE must be a positive integer, got: '${v}'`);
}

Type guard

function isValidPrefetchSize(v) { return v === undefined || (/^\d+$/.test(v.trim()) && Number(v.trim()) > 0); }

Try / catch

try {
  runIpcScan();
} catch (e) {
  if (String(e).includes('POLARS_RECORD_BATCH_PREFETCH_SIZE')) {
    delete process.env.POLARS_RECORD_BATCH_PREFETCH_SIZE;
    runIpcScan();
  } else throw e;
}

Prevention

When it happens

Trigger: Running a streaming IPC/Arrow file scan with POLARS_RECORD_BATCH_PREFETCH_SIZE set to '', '0', '-1', 'eight', or any string outside non-zero-usize range.

Common situations: Tuning prefetch in CI or Docker where the variable is declared but left empty in an env file, or pasting a value with units ('64 batches') from a benchmark script.

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


AI-assisted analysis of pola-rs/polars@fe841f959e (2026-09-18). Data as JSON: /api/errors/f1a5de619dd6f924. Report an issue: GitHub.

Appendix: source

Thrown at crates/polars-stream/src/nodes/io_sources/ipc/builder.rs:57

#[cfg(feature = "ipc")]
impl FileReaderBuilder for IpcReaderBuilder {
    fn reader_name(&self) -> &str {
        "ipc"
    }

    fn reader_capabilities(&self) -> ReaderCapabilities {
        use ReaderCapabilities as RC;

        RC::ROW_INDEX | RC::PRE_SLICE
    }

    fn set_execution_state(&self, execution_state: &crate::execute::StreamingExecutionState) {
        let prefetch_limit = std::env::var("POLARS_RECORD_BATCH_PREFETCH_SIZE")
            .map(|x| {
                x.parse::<NonZeroUsize>()
                    .unwrap_or_else(|_| {
                        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}")

View on GitHub (pinned to fe841f959e)