pola-rs/polars · error · TypeError

strategy is not supported for

Error message

{how!r} strategy is not supported for {qualified_type_name(elems[0])!r}

What it means

The chosen concat `how` strategy only supports DataFrame and LazyFrame sequences; when the elements are some other type (e.g. Series or Expr), `concat` raises TypeError naming the actual element type. This is the align/horizontal dispatch branch validating element kinds.

Solutions

  1. Use `how='vertical'` for Series concatenation
  2. Convert Series to DataFrames before using align/horizontal strategies
  3. Check the element type of the list before choosing a `how` strategy

Example fix

// before
pl.concat([s1, s2], how='align')
// after
pl.concat([s1.to_frame('a'), s2.to_frame('b')], how='align')
Defensive patterns

Strategy: type-guard

Validate before calling

if not all(isinstance(x, (pl.DataFrame, pl.LazyFrame)) for x in elems):
    raise TypeError('align/horizontal concat requires DataFrames or LazyFrames')

Type guard

def are_frames(elems: list) -> bool:
    return bool(elems) and all(isinstance(x, (pl.DataFrame, pl.LazyFrame)) for x in elems)

Try / catch

try:
    result = pl.concat(elems, how='align')
except TypeError as e:
    result = pl.concat([x.to_frame() if isinstance(x, pl.Series) else x for x in elems], how='align')

Prevention

When it happens

Trigger: Calling `pl.concat([series1, series2], how='align')` or any align/horizontal strategy on elements that are not DataFrames or LazyFrames.

Common situations: Mixing Series and DataFrame inputs into one concat call; passing a list where items were accidentally unwrapped (e.g. a Series instead of a one-column DataFrame); copying a Series concat snippet and changing `how`.

Understand the failure class

Background: "is not a compatible type" / "cannot merge" errors: when a value's type doesn't match what the library requires — this error's family across 65 libraries.

Related errors


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

Appendix: source

Thrown at py-polars/src/polars/functions/eager.py:233

    elems: Sequence[PolarsType] = list(items)

    if not elems:
        msg = "cannot concat empty list"
        raise ValueError(msg)

    if len(elems) == 1 and isinstance(
        elems[0], (pl.DataFrame, pl.Series, pl.LazyFrame)
    ):
        return elems[0]

    if how.startswith("align"):
        if not is_non_empty_sequence_of(
            elems, pl.DataFrame
        ) and not is_non_empty_sequence_of(  # type: ignore[redundant-expr]
            elems, pl.LazyFrame
        ):
            msg = f"{how!r} strategy is not supported for {qualified_type_name(elems[0])!r}"
            raise TypeError(msg)

        # establish common columns, maintaining the order in which they appear
        all_columns = list(chain.from_iterable(e.collect_schema() for e in elems))
        key = {v: k for k, v in enumerate(ordered_unique(all_columns))}
        output_column_order = list(key)
        common_cols = sorted(
            reduce(
                lambda x, y: set(x) & set(y),  # type: ignore[arg-type, return-value]
                chain(e.collect_schema() for e in elems),
            ),
            key=lambda k: key.get(k, 0),
        )
        # we require at least one key column for 'align' strategies
        if not common_cols:
            msg = f"{how!r} strategy requires at least one common column"
            raise InvalidOperationError(msg)

        # align frame data using a join, with no suffix-resolution (will raise

View on GitHub (pinned to fe841f959e)