{"record":{"id":"1499754eebe1501a","repo":"pola-rs/polars","slug":"did-not-expect-type-qualified-type-name-elems-0","errorCode":null,"errorMessage":"did not expect type: {qualified_type_name(elems[0])!r} in `concat`","messagePattern":"did not expect type: (.+?) in `concat`","errorType":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"py-polars/src/polars/functions/eager.py","lineNumber":374,"sourceCode":"                )\n            )\n        else:\n            allowed = \", \".join(repr(m) for m in get_args(ConcatMethod))\n            msg = f\"LazyFrame `how` must be one of {{{allowed}}}, got {how!r}\"\n            raise ValueError(msg)\n\n    elif is_non_empty_sequence_of(elems, pl.Series):\n        if how == \"vertical\":\n            out = wrap_s(plr.concat_series(elems))\n        else:\n            msg = \"Series only supports 'vertical' concat strategy\"\n            raise ValueError(msg)\n\n    elif is_non_empty_sequence_of(elems, pl.Expr):\n        return wrap_expr(plr.concat_expr([e._pyexpr for e in elems], rechunk))\n    else:\n        msg = f\"did not expect type: {qualified_type_name(elems[0])!r} in `concat`\"\n        raise TypeError(msg)\n\n    if rechunk:\n        return out.rechunk()\n    return out\n\n\ndef union(\n    items: Iterable[PolarsType],\n    *,\n    how: ConcatMethod = \"vertical\",\n    strict: bool | None = None,\n) -> PolarsType:\n    \"\"\"\n    Combine multiple DataFrames, LazyFrames, or Series into a single object.\n\n    .. warning::\n        This function does not guarantee any specific ordering of rows in the result.\n        If you need predictable row ordering, use `pl.concat()` instead.","sourceCodeStart":356,"sourceCodeEnd":392,"githubUrl":"https://github.com/pola-rs/polars/blob/fe841f959ef4d2ceefc05a310d33ed7b1ab24e5e/py-polars/src/polars/functions/eager.py#L356-L392","documentation":"`pl.concat` reached its final fallback without recognizing the element type: the sequence elements are none of DataFrame, LazyFrame, Series, or Expr, so it raises a TypeError naming the offending type. This is the exhaustiveness guard of the concat dispatcher.","triggerScenarios":"Calling `pl.concat([dict1, dict2])`, `pl.concat(['a', 'b'])`, or passing numpy arrays / plain lists of non-Polars objects.","commonSituations":"Forgetting to wrap raw data with `pl.DataFrame(...)`/`pl.Series(...)`; passing mixed lists where the first element slipped an earlier type check; a helper returning the wrong object type.","solutions":["Convert elements to a Polars type (DataFrame, Series, LazyFrame, or Expr) before concat","Inspect `type(items[0])` to identify the unexpected element type","Fix the producer of the list so it yields Polars objects"],"exampleFix":"// before\npl.concat([{'a': 1}, {'a': 2}])\n// after\npl.concat([pl.DataFrame([{'a': 1}]), pl.DataFrame([{'a': 2}])])","handlingStrategy":"type-guard","validationCode":"POLARS_TYPES = (pl.DataFrame, pl.LazyFrame, pl.Series, pl.Expr)\nif not all(isinstance(x, POLARS_TYPES) for x in items):\n    raise TypeError(f'unexpected element type: {type(items[0])!r}')","typeGuard":"def is_polars_concat_input(items: list) -> bool:\n    return bool(items) and all(\n        isinstance(x, (pl.DataFrame, pl.LazyFrame, pl.Series, pl.Expr)) for x in items\n    )","tryCatchPattern":"try:\n    result = pl.concat(items)\nexcept TypeError as e:\n    if 'did not expect type' in str(e):\n        result = pl.concat([pl.Series(x) if isinstance(x, (list, tuple)) else x for x in items])\n    else:\n        raise","preventionTips":["Convert raw data with pl.DataFrame/pl.Series at ingestion boundaries","Assert element types in helper functions with type annotations","Avoid heterogeneous lists passed to concat"],"tags":["polars","concat","type-error","unsupported-type"],"backgroundTag":"type-mismatch","analyzedSha":"fe841f959ef4d2ceefc05a310d33ed7b1ab24e5e","analyzedAt":"2026-09-18T22:14:11.667Z","contentChangedAt":"2026-09-18T22:14:11.667Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}