pola-rs/polars · error

could not parse table width argument

Error message

could not parse table width argument

What it means

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.

Solutions

  1. Fix the env var to a plain non-negative integer, e.g. export POLARS_TABLE_WIDTH=100
  2. Unset it to use the default (terminal width or 100 fallback): unset POLARS_TABLE_WIDTH or os.environ.pop('POLARS_TABLE_WIDTH', None)
  3. Use a negative value intentionally if unbounded width is desired (it maps to u16::MAX)

Example fix

// before
export POLARS_TABLE_WIDTH=auto
// after
export POLARS_TABLE_WIDTH=120
Defensive patterns

Strategy: validation

Validate before calling

import os
w = os.environ.get('POLARS_TABLE_WIDTH')
if w is not None:
    int(w)  # raises a clear ValueError before Polars panics

Type guard

def valid_table_width(v: str | None) -> bool:
    if v is None: return True
    try: int(v); return True
    except ValueError: return False

Try / catch

import os
if not valid_table_width(os.environ.get('POLARS_TABLE_WIDTH')):
    os.environ.pop('POLARS_TABLE_WIDTH', None)  # fall back to default width

Prevention

When it happens

Trigger: POLARS_TABLE_WIDTH set to a non-integer (e.g. 'auto', '', '80.5') and any DataFrame print/repr triggering fmt.

Common situations: Shell profile or notebook config exporting POLARS_TABLE_WIDTH incorrectly; copy-pasted settings with units ('100px'); empty string left in environment.

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


AI-assisted analysis of pola-rs/polars@fe841f959e (2026-09-18). Data as JSON: /api/errors/1ba99304adf63a7a. Report an issue: GitHub.

Appendix: source

Thrown at crates/polars-core/src/fmt.rs:747

                                &ellipsis,
                                padding,
                            );
                            table.add_row(row_strings);
                        } else {
                            break;
                        }
                    }
                }
            } else if height > 0 {
                let dots: Vec<String> = vec![ellipsis; self.width()];
                table.add_row(dots);
            }
            let tbl_fallback_width = 100;
            let tbl_width = std::env::var("POLARS_TABLE_WIDTH")
                .map(|s| {
                    let n = s
                        .parse::<i64>()
                        .expect("could not parse table width argument");
                    let w = if n < 0 {
                        u16::MAX
                    } else {
                        u16::try_from(n).expect("table width argument does not fit in u16")
                    };
                    Some(w)
                })
                .unwrap_or(None);

            // column width constraints
            let col_width_exact =
                |w: usize| ColumnConstraint::Absolute(comfy_table::Width::Fixed(w as u16));
            let col_width_bounds = |l: usize, u: usize| ColumnConstraint::Boundaries {
                lower: Width::Fixed(l as u16),
                upper: Width::Fixed(u as u16),
            };
            let min_col_width = std::cmp::max(5, 3 + padding);
            for (idx, elem_len) in max_elem_lengths.iter().enumerate() {

View on GitHub (pinned to fe841f959e)