{"record":{"id":"ab9a844063108596","repo":"pola-rs/polars","slug":"merge-sorted-is-not-supported-for-qualified-type","errorCode":null,"errorMessage":"merge_sorted is not supported for {qualified_type_name(elems[0])!r}","messagePattern":"merge_sorted is not supported for (.+?)","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"py-polars/src/polars/functions/eager.py","lineNumber":771,"sourceCode":"    row order when the key is equal between dataframes.\n\n    The key(s) must be sorted in ascending order.\n    \"\"\"\n    elems: Sequence[PolarsType] = list(items)\n\n    if not elems:\n        msg = \"cannot merge_sort empty list\"\n        raise ValueError(msg)\n    if len(elems) == 1 and isinstance(elems[0], (pl.DataFrame, pl.LazyFrame)):\n        return elems[0]\n\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\"merge_sorted is not supported for {qualified_type_name(elems[0])!r}\"\n        raise TypeError(msg)\n\n    frames = [df.lazy() for df in elems]\n\n    def reduce_fn(x: pl.LazyFrame, y: pl.LazyFrame) -> pl.LazyFrame:\n        return x.merge_sorted(y, key=key, maintain_order=maintain_order)\n\n    lf = reduce_balanced(reduce_fn, frames)\n    eager = isinstance(elems[0], pl.DataFrame)\n    return lf._collect_eager() if eager else lf  # type: ignore[return-value]\n\n\ndef _alignment_join(\n    *idx_frames: tuple[int, LazyFrame],\n    align_on: list[str],\n    how: JoinStrategy = \"full\",\n    descending: bool | Sequence[bool] = False,\n    eager: bool = False,\n) -> LazyFrame:","sourceCodeStart":753,"sourceCodeEnd":789,"githubUrl":"https://github.com/pola-rs/polars/blob/df599052daf96e7a9cc30a3b0c6bd25d6947e3c0/py-polars/src/polars/functions/eager.py#L753-L789","documentation":"Raised by pl.merge_sorted when the elements are not all DataFrame or all LazyFrame. The function merges pre-sorted frames on a key; Series and Expr have no merge_sorted representation at this level, so any other element type raises TypeError naming elems[0].","triggerScenarios":"pl.merge_sorted([s1, s2], key='ts'); a list mixing Series with DataFrames; passing column expressions instead of frames.","commonSituations":"Sorted-merge pipelines fed per-column Series by mistake; helpers that sometimes return frames and sometimes Series.","solutions":["For Series: concat then sort — pl.concat([s1, s2]).sort()","Or promote Series to named frames: pl.merge_sorted([s1.to_frame(), s2.to_frame()], key='ts')","Ensure every frame is actually sorted ascending on the key before merging"],"exampleFix":"# before\npl.merge_sorted([s1, s2], key='ts')  # TypeError\n\n# after\npl.concat([s1, s2]).sort()\n# or\npl.merge_sorted([s1.to_frame(), s2.to_frame()], key='ts')","handlingStrategy":"type-guard","validationCode":null,"typeGuard":"def merge_sortable(items) -> bool:\n    items = list(items)\n    return bool(items) and all(\n        isinstance(e, (pl.DataFrame, pl.LazyFrame)) for e in items\n    )","tryCatchPattern":null,"preventionTips":["Route Series through concat + sort instead of merge_sorted","Keep sorted-merge pipelines frame-based from ingestion onward"],"tags":["polars","merge-sorted","series","type-check"],"backgroundTag":null,"analyzedSha":"df599052daf96e7a9cc30a3b0c6bd25d6947e3c0","analyzedAt":"2026-08-16T12:10:03.978Z","schemaVersion":2},"datasetVersion":"2026-08-16T13:17:31.715Z"}