{"record":{"id":"c055c88abd7c830c","repo":"pola-rs/polars","slug":"invalid-value-for-polars-force-csv-infer-read-size","errorCode":null,"errorMessage":"invalid value for POLARS_FORCE_CSV_INFER_READ_SIZE: {x}","messagePattern":"invalid value for POLARS_FORCE_CSV_INFER_READ_SIZE: (.+?)","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/polars-io/src/csv/read/streaming.rs","lineNumber":409,"sourceCode":"/// Iterate over valid CSV lines produced by reader.\n///\n/// Returning `ConsumeDiscard` after `ConsumeKeep` is a logic error, since a segmented `Buffer`\n/// can't be constructed.\nfn for_each_line_from_reader_from_compressed_reader(\n    parse_options: &CsvParseOptions,\n    is_file_start: bool,\n    mut prev_leftover: Buffer<u8>,\n    initial_read_size: usize,\n    reader: &mut CompressedReader,\n    mut line_fn: impl FnMut(Buffer<u8>) -> PolarsResult<LineUse>,\n) -> PolarsResult<Buffer<u8>> {\n    let mut is_first_line = is_file_start;\n\n    let fixed_read_size = std::env::var(\"POLARS_FORCE_CSV_INFER_READ_SIZE\")\n        .map(|x| {\n            x.parse::<NonZeroUsize>()\n                .unwrap_or_else(|_| {\n                    panic!(\"invalid value for POLARS_FORCE_CSV_INFER_READ_SIZE: {x}\")\n                })\n                .get()\n        })\n        .ok();\n\n    let mut read_size = fixed_read_size.unwrap_or(initial_read_size);\n    let mut retain_offset = None;\n\n    loop {\n        let (mut slice, bytes_read) = reader.read_next_slice(&prev_leftover, read_size)?;\n        if slice.is_empty() {\n            return Ok(Buffer::new());\n        }\n\n        if is_first_line {\n            is_first_line = false;\n            const UTF8_BOM_MARKER: Option<&[u8]> = Some(b\"\\xef\\xbb\\xbf\");\n            if slice.get(0..3) == UTF8_BOM_MARKER {","sourceCodeStart":391,"sourceCodeEnd":427,"githubUrl":"https://github.com/pola-rs/polars/blob/fe841f959ef4d2ceefc05a310d33ed7b1ab24e5e/crates/polars-io/src/csv/read/streaming.rs#L391-L427","documentation":"This panic fires when the environment variable POLARS_FORCE_CSV_INFER_READ_SIZE is set to a value that cannot be parsed as a non-zero usize. The variable forces a fixed read size during CSV schema inference on compressed readers, overriding the adaptive initial_read_size. Because the value is consumed as configuration, Polars panics instead of ignoring the bad value.","triggerScenarios":"export POLARS_FORCE_CSV_INFER_READ_SIZE=0, 'abc', '4096.0', '-1', or an empty string; triggered in for_each_line_from_reader_from_compressed_reader (via read_until_start_and_infer_schema_from_compressed_reader) when reading compressed CSVs for schema inference.","commonSituations":"Users forcing deterministic read sizes to work around inference bugs on gzipped CSVs and mistyping the value; using units like '1KB'; stale values left in CI or .env files after the debugging session ends.","solutions":["Set POLARS_FORCE_CSV_INFER_READ_SIZE to a plain positive integer (e.g. 1048576) or unset it to use adaptive read sizing","Remove units, decimals, signs, and whitespace from the value","Verify the variable is not exported globally in shell profiles after temporary debugging"],"exampleFix":"// before\nexport POLARS_FORCE_CSV_INFER_READ_SIZE=1KB\n// after\nexport POLARS_FORCE_CSV_INFER_READ_SIZE=65536","handlingStrategy":"validation","validationCode":"const v = process.env.POLARS_FORCE_CSV_INFER_READ_SIZE;\nif (v !== undefined && !/^[0-9]+$/.test(v.trim())) throw new Error(`POLARS_FORCE_CSV_INFER_READ_SIZE must be a positive integer, got: ${v}`);","typeGuard":"function isValidReadSize(v) { return typeof v === 'string' && /^[1-9][0-9]*$/.test(v.trim()); }","tryCatchPattern":"// unset invalid tuning vars before running inference\nconst raw = process.env.POLARS_FORCE_CSV_INFER_READ_SIZE;\nif (raw && !/^\\d+$/.test(raw.trim())) { delete process.env.POLARS_FORCE_CSV_INFER_READ_SIZE; }","preventionTips":["Use plain positive integers in bytes; no KB/MB suffixes","Unset the variable after debugging compressed-CSV inference issues","Unset (not zero) to restore adaptive read sizing","Lint POLARS_* env vars in CI before running read_csv workloads"],"tags":["env-var","configuration","panic","csv"],"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"}