pola-rs/polars · error

`separator` must be a single character; found

Error message

`separator` must be a single character; found {separator!r}

What it means

Config context's decimal separator setter validates that separator is exactly one character; passing an empty string or multi-character string raises ValueError because it would corrupt numeric formatting.

Solutions

  1. Pass exactly one character, e.g. ',' or '.'
  2. Pass None to reset to default
  3. Strip/validate the string before calling

Example fix

// before
pl.Config.set_decimal_separator(', ')  # ValueError
// after
pl.Config.set_decimal_separator(',')
Defensive patterns

Strategy: validation

Validate before calling

assert isinstance(separator, str) and len(separator) == 1, separator

Type guard

def is_single_char(s: object) -> bool:
    return isinstance(s, str) and len(s) == 1

Try / catch

try:
    pl.Config.set_decimal_separator(sep)
except ValueError as e:
    logging.error('%s', e)
    raise

Prevention

When it happens

Trigger: pl.Config.set_decimal_separator(',') is fine, but set_decimal_separator(', ') or set_decimal_separator('..') raises ValueError.

Common situations: Copy-pasting a locale pattern like ', ' or '. '; passing an empty string (len 0 != 1 also fails).

Understand the failure class

Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.

Related errors


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

Appendix: source

Thrown at py-polars/src/polars/config.py:651

        ...     thousands_separator=".",
        ...     decimal_separator=",",
        ...     float_precision=3,
        ... ):
        ...     print(df)
        shape: (3, 1)
        ┌───────────────┐
        │             v │
        │           --- │
        │           f64 │
        ╞═══════════════╡
        │     9.876,543 │
        │ 1.010.101,000 │
        │  -123.456,780 │
        └───────────────┘
        """
        if isinstance(separator, str) and len(separator) != 1:
            msg = f"`separator` must be a single character; found {separator!r}"
            raise ValueError(msg)
        plr.set_decimal_separator(sep=separator)
        return cls

    @classmethod
    def set_thousands_separator(
        cls, separator: str | bool | None = None
    ) -> type[Config]:
        """
        Set the thousands grouping separator character.

        Parameters
        ----------
        separator : str, bool
            Set True to use the default "," (thousands) and "." (decimal) separators.
            Can also set a custom char, or set ``None`` to omit the separator.

        See Also
        --------

View on GitHub (pinned to fe841f959e)