pola-rs/polars · error · ValueError

Series only supports 'vertical' concat strategy

Error message

Series only supports 'vertical' concat strategy

What it means

Series can only be concatenated with the 'vertical' strategy (stacking end-to-end); any other `how` raises ValueError. Polars does not implement horizontal or diagonal concat for Series because they have no columns.

Solutions

  1. Use `pl.concat(series_list, how='vertical')`
  2. Build a DataFrame and use `hstack` for horizontal combination of Series
  3. Make the `how` parameter conditional on element type in generic wrappers

Example fix

// before
pl.concat([s1, s2], how='horizontal')
// after
pl.concat([s1, s2], how='vertical')
Defensive patterns

Strategy: validation

Validate before calling

if not all(isinstance(x, pl.Series) for x in items):
    raise TypeError('expected Series')
if how != 'vertical':
    raise ValueError("Series concat only supports how='vertical'")
result = pl.concat(items, how='vertical')

Type guard

def are_series(items: list) -> bool:
    return bool(items) and all(isinstance(x, pl.Series) for x in items)

Try / catch

try:
    result = pl.concat(series_list, how=how)
except ValueError as e:
    if 'vertical' in str(e):
        result = pl.concat(series_list, how='vertical')
    else:
        raise

Prevention

When it happens

Trigger: Calling `pl.concat([s1, s2], how='diagonal')` or any strategy other than 'vertical' on a sequence of Series.

Common situations: Copy-pasting a DataFrame concat call and only swapping in Series; attempting to 'hstack' Series (use `pl.DataFrame([...])` or `DataFrame.hstack` instead); generic concat wrappers that pass `how` through unconditionally.

Understand the failure class

Background: UnsupportedOperationException and "is not supported" errors: when a library deliberately refuses a call — this error's family across 30 libraries.

Related errors


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

Appendix: source

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

        elif how == "horizontal_extend":
            return wrap_ldf(
                plr.concat_lf_horizontal(
                    elems,
                    parallel=parallel,
                    strict=False,
                )
            )
        else:
            allowed = ", ".join(repr(m) for m in get_args(ConcatMethod))
            msg = f"LazyFrame `how` must be one of {{{allowed}}}, got {how!r}"
            raise ValueError(msg)

    elif is_non_empty_sequence_of(elems, pl.Series):
        if how == "vertical":
            out = wrap_s(plr.concat_series(elems))
        else:
            msg = "Series only supports 'vertical' concat strategy"
            raise ValueError(msg)

    elif is_non_empty_sequence_of(elems, pl.Expr):
        return wrap_expr(plr.concat_expr([e._pyexpr for e in elems], rechunk))
    else:
        msg = f"did not expect type: {qualified_type_name(elems[0])!r} in `concat`"
        raise TypeError(msg)

    if rechunk:
        return out.rechunk()
    return out


def union(
    items: Iterable[PolarsType],
    *,
    how: ConcatMethod = "vertical",
    strict: bool | None = None,
) -> PolarsType:

View on GitHub (pinned to fe841f959e)