{"record":{"id":"343524367d32c374","repo":"pola-rs/polars","slug":"invalid-value-for-polars-num-readers-pre-init-x","errorCode":null,"errorMessage":"invalid value for POLARS_NUM_READERS_PRE_INIT: {x}","messagePattern":"invalid value for POLARS_NUM_READERS_PRE_INIT: (.+?)","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/polars-stream/src/nodes/io_sources/multi_scan/functions/mod.rs","lineNumber":23,"sourceCode":"use polars_io::cloud::CloudOptions;\nuse polars_io::cloud::concurrency_config::FetchConfig;\nuse polars_io::metrics::IOMetrics;\nuse polars_io::utils::byte_source::{ByteSource, DynByteSourceBuilder};\nuse polars_io::utils::compression::SupportedCompression;\nuse polars_plan::dsl::ScanSource;\nuse polars_utils::slice_enum::Slice;\n\npub mod resolve_projections;\npub mod resolve_slice;\n\npub fn calc_n_readers_pre_init(\n    num_pipelines: usize,\n    num_sources: usize,\n    pre_slice: Option<&Slice>,\n) -> usize {\n    if let Ok(v) = std::env::var(\"POLARS_NUM_READERS_PRE_INIT\").map(|x| {\n        x.parse::<NonZeroUsize>()\n            .unwrap_or_else(|_| panic!(\"invalid value for POLARS_NUM_READERS_PRE_INIT: {x}\"))\n            .get()\n    }) {\n        return v;\n    }\n\n    let max_files_with_slice = match pre_slice {\n        // Calculate the max number of files assuming 1 row per file.\n        Some(v @ Slice::Positive { .. }) => v.end_position().max(1),\n        Some(Slice::Negative { .. }) | None => usize::MAX,\n    };\n\n    // Set this generously high, there are users who scan 10,000's of small files from the cloud.\n    num_pipelines\n        .saturating_add(3)\n        .min(max_files_with_slice)\n        .min(num_sources)\n        .clamp(1, 128)\n}","sourceCodeStart":5,"sourceCodeEnd":41,"githubUrl":"https://github.com/pola-rs/polars/blob/fe841f959ef4d2ceefc05a310d33ed7b1ab24e5e/crates/polars-stream/src/nodes/io_sources/multi_scan/functions/mod.rs#L5-L41","documentation":"Polars panics when POLARS_NUM_READERS_PRE_INIT is set but cannot be parsed as a non-zero usize. calc_n_readers_pre_init (called during multi-scan initialize) uses this variable to override the computed number of readers opened before the first file properties are known.","triggerScenarios":"Executing a multi-file scan (scan_parquet/scan_ipc on multiple files) with POLARS_NUM_READERS_PRE_INIT set to '', '0', 'none', or any value outside the non-zero usize range.","commonSituations":"Benchmarkers setting the variable to '0' expecting 'auto' behavior, or leaving it defined-but-empty in CI environment configuration.","solutions":["Set the variable to a positive integer (e.g. 4).","Unset it to let Polars compute readers from num_pipelines, num_sources, and pre_slice.","Sanitize CI/env-file config: remove variable lines with empty values."],"exampleFix":"// before\nPOLARS_NUM_READERS_PRE_INIT=0\n// after\nPOLARS_NUM_READERS_PRE_INIT=4  # or unset","handlingStrategy":"validation","validationCode":"const v = process.env.POLARS_NUM_READERS_PRE_INIT;\nif (v !== undefined && (!/^\\d+$/.test(v.trim()) || parseInt(v, 10) === 0)) {\n  throw new Error(`POLARS_NUM_READERS_PRE_INIT must be a positive integer, got: '${v}'`);\n}","typeGuard":"function isValidReaderCount(v) { return v === undefined || (/^\\d+$/.test(v.trim()) && Number(v.trim()) > 0); }","tryCatchPattern":"try {\n  runMultiFileScan();\n} catch (e) {\n  if (String(e).includes('POLARS_NUM_READERS_PRE_INIT')) {\n    delete process.env.POLARS_NUM_READERS_PRE_INIT;\n    runMultiFileScan();\n  } else throw e;\n}","preventionTips":["Never set to 0 to mean 'auto' — unset the variable instead.","Validate Polars env overrides in your job bootstrap script.","Keep tuning overrides documented with accepted formats."],"tags":["rust","env-var","multi-scan","config"],"backgroundTag":"invalid-env-var-value","analyzedSha":"fe841f959ef4d2ceefc05a310d33ed7b1ab24e5e","analyzedAt":"2026-09-18T22:14:11.667Z","contentChangedAt":"2026-09-18T22:14:11.667Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}