{"record":{"id":"25280efd3a8144ec","repo":"pola-rs/polars","slug":"cannot-concat-empty-list","errorCode":null,"errorMessage":"cannot concat empty list","messagePattern":"cannot concat empty list","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"py-polars/src/polars/functions/eager.py","lineNumber":219,"sourceCode":"    ╞═════╪══════╪══════╪═════╡\n    │ 1   ┆ null ┆ null ┆ 7   │\n    │ 3   ┆ null ┆ 6    ┆ 8   │\n    └─────┴──────┴──────┴─────┘\n    >>> pl.concat([df_a1, df_a2, df_a3], how=\"align_inner\")\n    shape: (0, 4)\n    ┌─────┬─────┬─────┬─────┐\n    │ id  ┆ x   ┆ y   ┆ z   │\n    │ --- ┆ --- ┆ --- ┆ --- │\n    │ i64 ┆ i64 ┆ i64 ┆ i64 │\n    ╞═════╪═════╪═════╪═════╡\n    └─────┴─────┴─────┴─────┘\n    \"\"\"  # noqa: W505\n    # unpack/standardise (handles generator input)\n    elems: Sequence[PolarsType] = list(items)\n\n    if not elems:\n        msg = \"cannot concat empty list\"\n        raise ValueError(msg)\n\n    if len(elems) == 1 and isinstance(\n        elems[0], (pl.DataFrame, pl.Series, pl.LazyFrame)\n    ):\n        return elems[0]\n\n    if how.startswith(\"align\"):\n        if not is_non_empty_sequence_of(\n            elems, pl.DataFrame\n        ) and not is_non_empty_sequence_of(  # type: ignore[redundant-expr]\n            elems, pl.LazyFrame\n        ):\n            msg = f\"{how!r} strategy is not supported for {qualified_type_name(elems[0])!r}\"\n            raise TypeError(msg)\n\n        # establish common columns, maintaining the order in which they appear\n        all_columns = list(chain.from_iterable(e.collect_schema() for e in elems))\n        key = {v: k for k, v in enumerate(ordered_unique(all_columns))}","sourceCodeStart":201,"sourceCodeEnd":237,"githubUrl":"https://github.com/pola-rs/polars/blob/fe841f959ef4d2ceefc05a310d33ed7b1ab24e5e/py-polars/src/polars/functions/eager.py#L201-L237","documentation":"`pl.concat` requires at least one item to concatenate; an empty sequence has no defined result shape, so `concat` raises ValueError. This is an upfront guard before any type or strategy dispatch happens.","triggerScenarios":"Calling `pl.concat([])`, `pl.concat(itertools.chain())`, or passing a generator/filtered list comprehension that produced zero matching items.","commonSituations":"Dynamic frame lists built by filtering an empty or fully-filtered-out collection; looping over an empty dict of sources; reading zero files and concatenating resulting frames.","solutions":["Check the list is non-empty before calling pl.concat","Return a fallback empty DataFrame/Series instead of concatenating an empty list","Fix the upstream filter/generator that yielded no items"],"exampleFix":"// before\nresult = pl.concat(frames)\n// after\nif not frames:\n    raise ValueError('no frames to concat')\nresult = pl.concat(frames)","handlingStrategy":"validation","validationCode":"frames = list(items)\nif not frames:\n    raise ValueError('no frames to concat')\nresult = pl.concat(frames)","typeGuard":"def is_concatable(items) -> bool:\n    return len(items) > 0 and all(isinstance(x, (pl.DataFrame, pl.LazyFrame, pl.Series)) for x in items)","tryCatchPattern":"try:\n    result = pl.concat(frames)\nexcept ValueError as e:\n    if 'empty list' in str(e):\n        result = pl.DataFrame()\n    else:\n        raise","preventionTips":["Materialize generators into lists and check length before concat","Return early from pipelines when upstream produced zero frames","Add unit tests for empty-input edge cases"],"tags":["polars","concat","empty-input"],"backgroundTag":"empty-required-field","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"}