pola-rs/polars · error

invalid value for POLARS_OVERRIDE_TOTAL_MEMORY

Error message

invalid value for POLARS_OVERRIDE_TOTAL_MEMORY: {s}

What it means

total_memory() lets users override the detected system memory via the POLARS_OVERRIDE_TOTAL_MEMORY environment variable; the value must parse as u64 bytes, otherwise it panics naming the invalid string.

Solutions

  1. Set POLARS_OVERRIDE_TOTAL_MEMORY to a plain integer number of bytes, e.g. 17179869184 for 16 GiB
  2. Unset the variable to fall back to auto-detected system memory
  3. Check the current value: echo $POLARS_OVERRIDE_TOTAL_MEMORY and fix or remove it

Example fix

// before
POLARS_OVERRIDE_TOTAL_MEMORY=16GB
// after
POLARS_OVERRIDE_TOTAL_MEMORY=17179869184
Defensive patterns

Strategy: validation

Validate before calling

import os
v = os.environ.get("POLARS_OVERRIDE_TOTAL_MEMORY")
if v is not None:
    assert v.isdigit() and int(v) < 2**64, f"POLARS_OVERRIDE_TOTAL_MEMORY must be a u64 byte count, got {v!r}"

Prevention

When it happens

Trigger: Setting POLARS_OVERRIDE_TOTAL_MEMORY to a non-numeric value (e.g. '8g' or '8GB') or to a value too large for u64.

Common situations: Users copying docs/examples expecting unit suffixes ('16GB'), typos in the numeric string, or setting the variable in CI with an invalid placeholder value.

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

Appendix: source

Thrown at crates/polars-utils/src/sys.rs:22

/// Return the total system memory in bytes.
pub fn total_memory() -> u64 {
    return *TOTAL_MEMORY;

    static TOTAL_MEMORY: LazyLock<u64> = LazyLock::new(|| {
        let mut sys = System::new();

        sys.refresh_memory_specifics(MemoryRefreshKind::nothing().with_ram());

        let mut v: u64 = match sys.cgroup_limits() {
            Some(limits) => limits.total_memory,
            None => sys.total_memory(),
        };

        if let Ok(s) = std::env::var("POLARS_OVERRIDE_TOTAL_MEMORY") {
            v = s
                .parse::<u64>()
                .unwrap_or_else(|_| panic!("invalid value for POLARS_OVERRIDE_TOTAL_MEMORY: {s}"))
        }

        if polars_config::config().verbose() {
            let gib = (v as f64) / (1024.0 * 1024.0 * 1024.0);
            eprintln!("total memory: {gib:.3} GiB ({v} bytes)")
        }

        v
    });
}

/// Startup system is expensive, so we do it once
pub struct MemInfo {
    sys: Mutex<System>,
}

impl MemInfo {
    /// This call is quite expensive, cache the results.

View on GitHub (pinned to fe841f959e)