{"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":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"py-polars/src/polars/functions/eager.py","lineNumber":375,"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":357,"sourceCodeEnd":393,"githubUrl":"https://github.com/pola-rs/polars/blob/df599052daf96e7a9cc30a3b0c6bd25d6947e3c0/py-polars/src/polars/functions/eager.py#L357-L393","documentation":"Raised by pl.concat when the input list is not a homogeneous sequence of DataFrame, LazyFrame, Series, or Expr. The dispatcher tests each type in turn (is_non_empty_sequence_of); when all fail it raises TypeError naming the qualified type of elems[0], e.g. 'builtins.str', 'numpy.ndarray', 'NoneType'.","triggerScenarios":"pl.concat([df, lf]) mixing DataFrame and LazyFrame; pl.concat(['a', 'b']); passing a dict or dict.keys() instead of its values; a numpy array or list-of-lists; a generator that yields non-frame objects.","commonSituations":"Passing a dict of frames instead of list(d.values()); mixing eager frames (read_parquet) with lazy ones (scan_parquet) from different pipeline stages; forgetting list() around a generator whose content is unknown; passing raw Python containers where frames were expected.","solutions":["Make all elements the same type: collect LazyFrames (lf.collect()) or make DataFrames lazy (df.lazy())","Wrap mapping values: pl.concat(list(frames_by_name.values()))","Materialize generators with list() first so type dispatch inspects real items and mixed types become visible"],"exampleFix":"# before\npl.concat([df1, lf2])        # TypeError\npl.concat(frames_by_name)     # dict -> TypeError\n\n# after\npl.concat([df1, lf2.collect()])\npl.concat(list(frames_by_name.values()))","handlingStrategy":"type-guard","validationCode":null,"typeGuard":"def is_concatable(items) -> bool:\n    items = list(items)\n    if not items:\n        return False\n    first = type(items[0])\n    return first in (pl.DataFrame, pl.LazyFrame, pl.Series, pl.Expr) and all(\n        type(e) is first for e in items\n    )","tryCatchPattern":null,"preventionTips":["Annotate helper params as list[pl.DataFrame] and convert once at the boundary","Always call list() on generators before pl.concat so mixed types surface early","Pass dict values, never the dict itself"],"tags":["polars","concat","type-check","api-misuse"],"backgroundTag":null,"analyzedSha":"df599052daf96e7a9cc30a3b0c6bd25d6947e3c0","analyzedAt":"2026-08-16T12:10:03.978Z","schemaVersion":2},"datasetVersion":"2026-08-16T13:17:31.715Z"}