pola-rs/polars · error
invalid POLARS_REGEX_SIZE_LIMIT
Error message
invalid POLARS_REGEX_SIZE_LIMIT
What it means
get_size_limit reads POLARS_REGEX_SIZE_LIMIT and calls .expect("invalid POLARS_REGEX_SIZE_LIMIT"), so a non-empty value that fails to parse as usize panics. This env var caps the total size of Polars' regex compilation cache.
Solutions
- Set POLARS_REGEX_SIZE_LIMIT to a plain integer number of bytes, e.g. 10485760
- Unset the variable or leave it empty to use the default cache limit
- Pre-parse the value with str::parse::<usize>() in a wrapper before launch to validate
- Do not use size suffixes or separators; convert units yourself
Example fix
// before os.environ["POLARS_REGEX_SIZE_LIMIT"] = "10MB" // after os.environ["POLARS_REGEX_SIZE_LIMIT"] = str(10 * 1024 * 1024)
Defensive patterns
Strategy: validation
Validate before calling
raw = os.environ.get("POLARS_REGEX_SIZE_LIMIT")
if raw:
try:
int(raw)
except ValueError:
raise ValueError(f"POLARS_REGEX_SIZE_LIMIT must be a plain integer (bytes), got {raw!r}") Prevention
- Use plain byte-count integers, no 'MB' suffixes or separators
- Leave the var empty/unset to use the default
- Convert units in your own config code before setting
- Validate numeric env vars at application startup
When it happens
Trigger: POLARS_REGEX_SIZE_LIMIT set to something non-numeric (e.g. '10MB', 'abc', '1_000') or negative, then triggering regex compilation through the cache (compile path) on string-matching operations.
Common situations: Assuming byte-size suffixes like '10MB' are accepted; thousands separators or underscores; empty var works (filtered out) but whitespace-only or garbage values do not.
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_PYTHON_SCAN_RESOLVE_THREADS
- could not parse table width argument
- creating extension types not allowed - try setting the…
- integer
- invalid value for
AI-assisted analysis of pola-rs/polars@fe841f959e (2026-09-18).
Data as JSON: /api/errors/2944c22f396bf642.
Report an issue: GitHub.
Appendix: source
Thrown at crates/polars-utils/src/regex_cache.rs:13
use std::cell::RefCell;
use regex::{Regex, RegexBuilder};
use crate::cache::LruCache;
fn get_size_limit() -> Option<usize> {
Some(
std::env::var("POLARS_REGEX_SIZE_LIMIT")
.ok()
.filter(|l| !l.is_empty())?
.parse()
.expect("invalid POLARS_REGEX_SIZE_LIMIT"),
)
}
// Regex compilation is really heavy, and the resulting regexes can be large as
// well, so we should have a good caching scheme.
//
// TODO: add larger global cache which has time-based flush.
/// A cache for compiled regular expressions.
pub struct RegexCache {
cache: LruCache<String, Regex>,
size_limit: Option<usize>,
}
impl RegexCache {
fn new() -> Self {
Self {
cache: LruCache::with_capacity(32),View on GitHub (pinned to fe841f959e)