pola-rs/polars · error · ValueError
DataFrame `how` must be one of
Error message
DataFrame `how` must be one of {{{allowed}}}, got {how!r} What it means
When concatenating DataFrames, `how` must be one of the valid `ConcatMethod` literals; any other string raises a ValueError enumerating the allowed values. This is the final else-branch of the DataFrame dispatch in `concat`.
Solutions
- Use one of the allowed strategies: 'vertical', 'vertical_relaxed', 'diagonal', 'diagonal_relaxed', 'horizontal', 'horizontal_extend', 'align', or align_* variants
- Fix casing/typo in the `how` argument
- Check `typing.get_args(polars.concatenate.ConcatMethod)` for the exact list
Example fix
// before pl.concat(dfs, how='hstack') // after pl.concat(dfs, how='horizontal')
Defensive patterns
Strategy: validation
Validate before calling
from typing import get_args
from polars.type_aliases import ConcatMethod
if how not in get_args(ConcatMethod):
raise ValueError(f'invalid how={how!r}') Type guard
def is_valid_how(how: str) -> bool:
from typing import get_args
from polars.type_aliases import ConcatMethod
return how in get_args(ConcatMethod) Try / catch
try:
result = pl.concat(dfs, how=how)
except ValueError as e:
if 'DataFrame `how` must be one of' in str(e):
result = pl.concat(dfs, how='vertical')
else:
raise Prevention
- Use the ConcatMethod Literal type annotation so static checkers catch bad values
- Copy strategy names from documentation, not memory
- Add an enum/constant list for allowed strategies in shared code
When it happens
Trigger: Calling `pl.concat(dfs, how='Horizontal')` (wrong case), `how='hstack'`, or any misspelled/unsupported strategy string on a list of DataFrames.
Common situations: Typos or wrong casing in `how`; copy-pasted strategies from other libraries (e.g. pandas `axis=` idioms); using a strategy valid for LazyFrame-only paths on DataFrames.
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
- LazyFrame `how` must be one of
- {}
- `strict` cannot be used with `how='horizontal_extend'`
- cannot concat empty list
- cannot create DataFrame from array with more than two…
AI-assisted analysis of pola-rs/polars@fe841f959e (2026-09-18).
Data as JSON: /api/errors/efee0efffeadff44.
Report an issue: GitHub.
Appendix: source
Thrown at py-polars/src/polars/functions/eager.py:317
out = wrap_df(plr.concat_df_diagonal(elems))
elif how == "diagonal_relaxed":
out = wrap_ldf(
plr.concat_lf_diagonal(
[df.lazy() for df in elems],
rechunk=rechunk,
parallel=parallel,
to_supertypes=True,
maintain_order=True,
)
)._collect_eager(optimizations=QueryOptFlags._eager())
elif how == "horizontal":
out = wrap_df(plr.concat_df_horizontal(elems, strict=True))
elif how == "horizontal_extend":
out = wrap_df(plr.concat_df_horizontal(elems, strict=False))
else:
allowed = ", ".join(repr(m) for m in get_args(ConcatMethod))
msg = f"DataFrame `how` must be one of {{{allowed}}}, got {how!r}"
raise ValueError(msg)
elif is_non_empty_sequence_of(elems, pl.LazyFrame):
how = _normalize_horizontal_concat("concat", how, strict=strict)
if how in ("vertical", "vertical_relaxed"):
return wrap_ldf(
plr.concat_lf(
elems,
rechunk=rechunk,
parallel=parallel,
to_supertypes=how.endswith("relaxed"),
maintain_order=True,
)
)
elif how in ("diagonal", "diagonal_relaxed"):
return wrap_ldf(
plr.concat_lf_diagonal(
elems,View on GitHub (pinned to fe841f959e)