pola-rs/polars · error · ValueError

`orient` must be one of

Error message

`orient` must be one of {{'col', 'row', None}}, got {orient!r}

What it means

Raised by _sequence_of_sequence_to_pydf when the `orient` argument is not 'col', 'row', or None. Orient controls whether inner sequences are interpreted as rows or columns, and any other string is rejected with ValueError.

Solutions

  1. Use orient='col', orient='row', or orient=None exactly
  2. Remove the orient argument and rely on the default inference
  3. Map legacy values before calling, e.g. {'columns':'col','index':'row'}.get(orient)

Example fix

// before
pl.DataFrame([[1, 2], [3, 4]], orient='columns')
// after
pl.DataFrame([[1, 2], [3, 4]], orient='col')
Defensive patterns

Strategy: validation

Validate before calling

assert orient in ('col', 'row', None), f'orient must be col|row|None, got {orient!r}'

Type guard

def valid_orient(orient: str | None) -> bool:
    return orient in ('col', 'row', None)

Try / catch

try:
    df = pl.DataFrame(rows, orient=orient)
except ValueError as e:
    if 'orient' in str(e) and 'must be one of' in str(e):
        df = pl.DataFrame(rows, orient='row')
    else:
        raise

Prevention

When it happens

Trigger: pl.DataFrame([[1,2],[3,4]], orient='columns') — using a value like 'columns', 'rows', or 'auto' instead of the exact allowed strings; reached via _sequence_of_tuple_to_pydf or _sequence_of_numpy_to_pydf.

Common situations: Translating from pandas-style orient values such as 'index'/'columns' that polars does not accept, typos like 'cols', dynamic orient values read from config.

Understand the failure class

Background: Invalid enum value errors: "Unknown type", "Invalid scope", "must be one of" — when a string is not on the library's allowed list — this error's family across 23 libraries.

Related errors


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

Appendix: source

Thrown at py-polars/src/polars/_utils/construction/dataframe.py:638

    elif orient == "col":
        column_names, schema_overrides = _unpack_schema(
            schema, schema_overrides=schema_overrides, n_expected=len(data)
        )
        data_series: list[PySeries] = [
            pl.Series(
                column_names[i],
                element,
                dtype=schema_overrides.get(column_names[i]),
                strict=strict,
                nan_to_null=nan_to_null,
            )._s
            for i, element in enumerate(data)
        ]
        return PyDataFrame(data_series)

    else:
        msg = f"`orient` must be one of {{'col', 'row', None}}, got {orient!r}"
        raise ValueError(msg)


def _sequence_of_series_to_pydf(
    first_element: Series,  # noqa: ARG001
    data: Sequence[Any],
    schema: SchemaDefinition | None,
    *,
    schema_overrides: SchemaDict | None,
    strict: bool,
    **kwargs: Any,  # noqa: ARG001
) -> PyDataFrame:
    series_names = [s.name for s in data]
    column_names, schema_overrides = _unpack_schema(
        schema or series_names,
        schema_overrides=schema_overrides,
        n_expected=len(data),
    )
    data_series: list[PySeries] = []

View on GitHub (pinned to fe841f959e)