pola-rs/polars · error

invalid value for POLARS_ROW_GROUP_PREFETCH_KBYTES_BUDGET

Error message

invalid value for POLARS_ROW_GROUP_PREFETCH_KBYTES_BUDGET: {x}

What it means

Polars panics when POLARS_ROW_GROUP_PREFETCH_KBYTES_BUDGET is set but cannot be parsed as a non-zero usize. This variable caps the total kilobytes of Parquet row-group data prefetched concurrently. The default derives from num_pipelines and the FetchConfig chunk size; an unparseable or zero user value triggers this panic in set_execution_state.

Solutions

  1. Unset POLARS_ROW_GROUP_PREFETCH_KBYTES_BUDGET to use the computed default
  2. Set it to a plain positive decimal integer of kilobytes, e.g. export POLARS_ROW_GROUP_PREFETCH_KBYTES_BUDGET=65536
  3. Ensure no units, spaces, or surrounding quotes are included in the value

Example fix

// before
POLARS_ROW_GROUP_PREFETCH_KBYTES_BUDGET=""
// after
POLARS_ROW_GROUP_PREFETCH_KBYTES_BUDGET=65536
Defensive patterns

Strategy: validation

Validate before calling

// Rust: validate before running the scan
if let Ok(v) = std::env::var("POLARS_ROW_GROUP_PREFETCH_KBYTES_BUDGET") {
    assert!(v.parse::<NonZeroUsize>().is_ok(), "POLARS_ROW_GROUP_PREFETCH_KBYTES_BUDGET must be a positive integer (kilobytes), got: {v}");
}

Type guard

fn valid_kbytes_budget(v: &str) -> bool { v.parse::<NonZeroUsize>().is_ok() }

Prevention

When it happens

Trigger: Setting POLARS_ROW_GROUP_PREFETCH_KBYTES_BUDGET to a non-numeric string ('512MB'), zero, a negative number, or a value exceeding usize::MAX before a streaming Parquet scan.

Common situations: Users express the budget with unit suffixes ('64k', '1G'), or set 0 expecting 'no limit'; CI config templating injects empty strings or 'None'.

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/b3a1d264ca3ed8c7. Report an issue: GitHub.

Appendix: source

Thrown at crates/polars-stream/src/nodes/io_sources/parquet/builder.rs:102

                    .max(get_request_budget() as usize)
                    .clamp(16, 2048),
            )
            .max(1);

        // Bound the max memory in use for the pipeline.
        // This should be large enough to be non-blocking, but small enough to avoid
        // excessive memory use from a run-away prefetch pipeline.
        // "Correct" formula: (a) max effective in-flight bdp-based bytes budget + (b) decode pipeline.
        // Since we do not know (a) at startup, we use  '3 * (b) + buffer' as a proxy for (a), where the
        // multiplier reflects the max gain factor for in-flight control.
        // TODO: Dynamically adapt the max memory to the observed BDP.
        // NOTE: This does not account for the decompression multiplier, so actual memory
        // usage can be substantially larger.
        let prefetch_kbytes_limit = std::env::var("POLARS_ROW_GROUP_PREFETCH_KBYTES_BUDGET")
            .map(|x| {
                x.parse::<NonZeroUsize>()
                    .unwrap_or_else(|_| {
                        panic!("invalid value for POLARS_ROW_GROUP_PREFETCH_KBYTES_BUDGET: {x}")
                    })
                    .get()
            })
            .unwrap_or({
                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!(
                "[ParquetReaderBuilder]: prefetch_limit: {}, prefetch_kbytes_limit: {}",
                prefetch_limit, prefetch_kbytes_limit
            );
        }

        self.pipeline_budget

View on GitHub (pinned to fe841f959e)