{"record":{"id":"1ba99304adf63a7a","repo":"pola-rs/polars","slug":"could-not-parse-table-width-argument","errorCode":null,"errorMessage":"could not parse table width argument","messagePattern":"could not parse table width argument","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/polars-core/src/fmt.rs","lineNumber":747,"sourceCode":"                                &ellipsis,\n                                padding,\n                            );\n                            table.add_row(row_strings);\n                        } else {\n                            break;\n                        }\n                    }\n                }\n            } else if height > 0 {\n                let dots: Vec<String> = vec![ellipsis; self.width()];\n                table.add_row(dots);\n            }\n            let tbl_fallback_width = 100;\n            let tbl_width = std::env::var(\"POLARS_TABLE_WIDTH\")\n                .map(|s| {\n                    let n = s\n                        .parse::<i64>()\n                        .expect(\"could not parse table width argument\");\n                    let w = if n < 0 {\n                        u16::MAX\n                    } else {\n                        u16::try_from(n).expect(\"table width argument does not fit in u16\")\n                    };\n                    Some(w)\n                })\n                .unwrap_or(None);\n\n            // column width constraints\n            let col_width_exact =\n                |w: usize| ColumnConstraint::Absolute(comfy_table::Width::Fixed(w as u16));\n            let col_width_bounds = |l: usize, u: usize| ColumnConstraint::Boundaries {\n                lower: Width::Fixed(l as u16),\n                upper: Width::Fixed(u as u16),\n            };\n            let min_col_width = std::cmp::max(5, 3 + padding);\n            for (idx, elem_len) in max_elem_lengths.iter().enumerate() {","sourceCodeStart":729,"sourceCodeEnd":765,"githubUrl":"https://github.com/pola-rs/polars/blob/fe841f959ef4d2ceefc05a310d33ed7b1ab24e5e/crates/polars-core/src/fmt.rs#L729-L765","documentation":"Polars' table formatter reads the POLARS_TABLE_WIDTH environment variable and parses it as i64; a non-numeric value makes .parse::<i64>() fail and the .expect panics with this message. It is a bad env-var value, not a data or query problem.","triggerScenarios":"POLARS_TABLE_WIDTH set to a non-integer (e.g. 'auto', '', '80.5') and any DataFrame print/repr triggering fmt.","commonSituations":"Shell profile or notebook config exporting POLARS_TABLE_WIDTH incorrectly; copy-pasted settings with units ('100px'); empty string left in environment.","solutions":["Fix the env var to a plain non-negative integer, e.g. export POLARS_TABLE_WIDTH=100","Unset it to use the default (terminal width or 100 fallback): unset POLARS_TABLE_WIDTH or os.environ.pop('POLARS_TABLE_WIDTH', None)","Use a negative value intentionally if unbounded width is desired (it maps to u16::MAX)"],"exampleFix":"// before\nexport POLARS_TABLE_WIDTH=auto\n// after\nexport POLARS_TABLE_WIDTH=120","handlingStrategy":"validation","validationCode":"import os\nw = os.environ.get('POLARS_TABLE_WIDTH')\nif w is not None:\n    int(w)  # raises a clear ValueError before Polars panics","typeGuard":"def valid_table_width(v: str | None) -> bool:\n    if v is None: return True\n    try: int(v); return True\n    except ValueError: return False","tryCatchPattern":"import os\nif not valid_table_width(os.environ.get('POLARS_TABLE_WIDTH')):\n    os.environ.pop('POLARS_TABLE_WIDTH', None)  # fall back to default width","preventionTips":["Only set POLARS_TABLE_WIDTH to plain integers (no units, no blanks)","Sanitize env in notebooks/shell profiles before importing polars","Unset rather than mis-set when unsure — defaults are safe"],"tags":["polars","rust","environment-variable","formatting"],"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"}