{"record":{"id":"54986bba5064ae78","repo":"pola-rs/polars","slug":"input-frames-must-be-of-a-consistent-type-all-laz","errorCode":null,"errorMessage":"input frames must be of a consistent type (all LazyFrame or all DataFrame)","messagePattern":"input frames must be of a consistent type \\(all LazyFrame or all DataFrame\\)","errorType":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"py-polars/src/polars/functions/eager.py","lineNumber":978,"sourceCode":"    ├╌╌╌╌╌╌╌┤\n    │ 167.5 │\n    ├╌╌╌╌╌╌╌┤\n    │ 47.0  │\n    └───────┘\n    \"\"\"  # noqa: W505\n    if not frames:\n        return []\n\n    if len(frames) == 1 and not isinstance(frames[0], (pl.DataFrame, pl.LazyFrame)):\n        frames = frames[0]  # type: ignore[assignment]\n    if isinstance(frames, (Generator, Iterator)):\n        frames = tuple(frames)\n\n    if len({type(f) for f in frames}) != 1:\n        msg = (\n            \"input frames must be of a consistent type (all LazyFrame or all DataFrame)\"\n        )\n        raise TypeError(msg)\n\n    eager = isinstance(frames[0], pl.DataFrame)\n    on = [on] if (isinstance(on, str) or not isinstance(on, Sequence)) else on\n    align_on = [(c.meta.output_name() if isinstance(c, pl.Expr) else c) for c in on]\n\n    # create aligned master frame (this is the most expensive part; after\n    # we just select out the columns representing the component frames)\n    idx_frames = [(idx, frame.lazy()) for idx, frame in enumerate(frames)]  # type: ignore[union-attr]\n    alignment_frame = _alignment_join(\n        *idx_frames, align_on=align_on, how=how, descending=descending, eager=eager\n    )\n\n    # select-out aligned components from the master frame\n    aligned_cols = set(alignment_frame.collect_schema())\n    aligned_frames = []\n    for idx, lf in idx_frames:\n        sfx = f\":{idx}\"\n        df_cols = [","sourceCodeStart":960,"sourceCodeEnd":996,"githubUrl":"https://github.com/pola-rs/polars/blob/fe841f959ef4d2ceefc05a310d33ed7b1ab24e5e/py-polars/src/polars/functions/eager.py#L960-L996","documentation":"`pl.align_frames` aligns all input frames on shared key columns, so every frame must be the same kind: all DataFrames or all LazyFrames. Mixed inputs raise this TypeError because the alignment/return path differs by type.","triggerScenarios":"pl.align_frames(df, lf1) or a list built from mixed sources (some .collect()ed, some not).","commonSituations":"Pipeline stages where some frames were collected eagerly and others stayed lazy; forgetting .lazy() or .collect() on one frame.","solutions":["Make all frames lazy: pass [f.lazy() for f in frames]","Or make all eager: pass [f.collect() if isinstance(f, pl.LazyFrame) else f for f in frames]","Normalize at the pipeline boundary so downstream code sees one frame type"],"exampleFix":"// before\npl.align_frames(df1, lf2, on='id')\n// after\npl.align_frames(df1, lf2.collect(), on='id')","handlingStrategy":"type-guard","validationCode":"assert frames and len({type(f) for f in frames}) == 1, 'align_frames requires a single frame type'","typeGuard":"def is_homogeneous_frames(frames) -> bool:\n    return bool(frames) and len({type(f) for f in frames}) == 1 and isinstance(frames[0], (pl.DataFrame, pl.LazyFrame))","tryCatchPattern":"try:\n    aligned = pl.align_frames(*frames, on='id')\nexcept TypeError as e:\n    frames = [f.lazy() for f in frames]  # normalize then retry\n    aligned = pl.align_frames(*frames, on='id')","preventionTips":["Pick lazy or eager per pipeline stage and stick to it","Normalize with .lazy() or .collect() at function entry","Add a schema/type assertion in pipeline tests"],"tags":["polars","align-frames","type-error"],"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"}