pola-rs/polars · error
invalid value for POLARS_MEMORY_PREFETCH
Error message
invalid value for POLARS_MEMORY_PREFETCH: {v} What it means
Polars panics with 'invalid value for POLARS_MEMORY_PREFETCH: {v}' when the env var holds an unrecognized string. get_memory_prefetch_func matches against a fixed set of strategy names (no_prefetch, prefetch_l2, madvise_willneed, madvise_populate_read, force_populate_read) and rejects anything else at startup.
Solutions
- Set POLARS_MEMORY_PREFETCH to one of: no_prefetch, prefetch_l2, madvise_willneed (Unix), madvise_populate_read (Linux), force_populate_read
- Unset the variable entirely to use the default strategy
- Check spelling and lowercase casing exactly as documented
- echo/print the value early in the process to confirm what is actually set
Example fix
// before os.environ["POLARS_MEMORY_PREFETCH"] = "MADVISE_WILLNEED" # wrong case // after os.environ["POLARS_MEMORY_PREFETCH"] = "madvise_willneed"
Defensive patterns
Strategy: validation
Validate before calling
VALID = {"no_prefetch","prefetch_l2","madvise_willneed","madvise_populate_read","force_populate_read"}
v = os.environ.get("POLARS_MEMORY_PREFETCH")
if v is not None and v not in VALID:
raise ValueError(f"POLARS_MEMORY_PREFETCH must be one of {sorted(VALID)}, got {v!r}") Prevention
- Copy accepted values exactly from the documentation (lowercase)
- Default to unsetting the var if unsure
- Centralize tuning env vars in one validated settings module
- Re-validate accepted values after upgrading polars
When it happens
Trigger: POLARS_MEMORY_PREFETCH set to a typo'd or unknown value (e.g. 'willneed', 'prefetch', 'MADVISE_WILLNEED', empty-but-set string) before any memory-mapped read via begin_read.
Common situations: Typo in shell profile; case-sensitivity mistakes; stale values from an older Polars version whose accepted names changed; copy-paste from a different library's tuning guide.
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
- integer
- Invalid value for `POLARS_FORCE_PKG` variable
- invalid value for POLARS_NDJSON_CHUNK_SIZE
- Invalid value for `POLARS_PREFER_PKG` variable
- invalid value for POLARS_ROW_GROUP_PREFETCH_KBYTES_BUDGET
AI-assisted analysis of pola-rs/polars@fe841f959e (2026-09-18).
Data as JSON: /api/errors/b5fc7b911836135e.
Report an issue: GitHub.
Appendix: source
Thrown at crates/polars-utils/src/mem.rs:156
panic!(
"POLARS_MEMORY_PREFETCH=madvise_willneed is not supported by this system"
);
}
},
Some("madvise_populate_read") => {
#[cfg(target_os = "linux")]
{
madvise_populate_read
}
#[cfg(not(target_os = "linux"))]
{
panic!(
"POLARS_MEMORY_PREFETCH=madvise_populate_read is not supported by this system"
);
}
},
Some("force_populate_read") => force_populate_read,
Some(v) => panic!("invalid value for POLARS_MEMORY_PREFETCH: {v}"),
};
if verbose {
let func_name = match memory_prefetch_func as usize {
v if v == no_prefetch as *const () as usize => "no_prefetch",
v if v == prefetch_l2 as *const () as usize => "prefetch_l2",
v if v == madvise_sequential as *const () as usize => "madvise_sequential",
v if v == madvise_willneed as *const () as usize => "madvise_willneed",
v if v == madvise_populate_read as *const () as usize => "madvise_populate_read",
v if v == force_populate_read as *const () as usize => "force_populate_read",
_ => unreachable!(),
};
eprintln!("memory prefetch function: {func_name}");
}
memory_prefetch_func
}View on GitHub (pinned to fe841f959e)