pola-rs/polars · error · TypeError

input frames must be of a consistent type (all LazyFrame or…

Error message

input frames must be of a consistent type (all LazyFrame or all DataFrame)

What it means

`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.

Solutions

  1. Make all frames lazy: pass [f.lazy() for f in frames]
  2. Or make all eager: pass [f.collect() if isinstance(f, pl.LazyFrame) else f for f in frames]
  3. Normalize at the pipeline boundary so downstream code sees one frame type

Example fix

// before
pl.align_frames(df1, lf2, on='id')
// after
pl.align_frames(df1, lf2.collect(), on='id')
Defensive patterns

Strategy: type-guard

Validate before calling

assert frames and len({type(f) for f in frames}) == 1, 'align_frames requires a single frame type'

Type guard

def is_homogeneous_frames(frames) -> bool:
    return bool(frames) and len({type(f) for f in frames}) == 1 and isinstance(frames[0], (pl.DataFrame, pl.LazyFrame))

Try / catch

try:
    aligned = pl.align_frames(*frames, on='id')
except TypeError as e:
    frames = [f.lazy() for f in frames]  # normalize then retry
    aligned = pl.align_frames(*frames, on='id')

Prevention

When it happens

Trigger: pl.align_frames(df, lf1) or a list built from mixed sources (some .collect()ed, some not).

Common situations: Pipeline stages where some frames were collected eagerly and others stayed lazy; forgetting .lazy() or .collect() on one frame.

Understand the failure class

Background: Type mismatch errors: IllegalArgumentException, TypeError and type guards across 150 open-source libraries — this error's family across 150 libraries.

Related errors


AI-assisted analysis of pola-rs/polars@fe841f959e (2026-09-18). Data as JSON: /api/errors/54986bba5064ae78. Report an issue: GitHub.

Appendix: source

Thrown at py-polars/src/polars/functions/eager.py:978

    ├╌╌╌╌╌╌╌┤
    │ 167.5 │
    ├╌╌╌╌╌╌╌┤
    │ 47.0  │
    └───────┘
    """  # noqa: W505
    if not frames:
        return []

    if len(frames) == 1 and not isinstance(frames[0], (pl.DataFrame, pl.LazyFrame)):
        frames = frames[0]  # type: ignore[assignment]
    if isinstance(frames, (Generator, Iterator)):
        frames = tuple(frames)

    if len({type(f) for f in frames}) != 1:
        msg = (
            "input frames must be of a consistent type (all LazyFrame or all DataFrame)"
        )
        raise TypeError(msg)

    eager = isinstance(frames[0], pl.DataFrame)
    on = [on] if (isinstance(on, str) or not isinstance(on, Sequence)) else on
    align_on = [(c.meta.output_name() if isinstance(c, pl.Expr) else c) for c in on]

    # create aligned master frame (this is the most expensive part; after
    # we just select out the columns representing the component frames)
    idx_frames = [(idx, frame.lazy()) for idx, frame in enumerate(frames)]  # type: ignore[union-attr]
    alignment_frame = _alignment_join(
        *idx_frames, align_on=align_on, how=how, descending=descending, eager=eager
    )

    # select-out aligned components from the master frame
    aligned_cols = set(alignment_frame.collect_schema())
    aligned_frames = []
    for idx, lf in idx_frames:
        sfx = f":{idx}"
        df_cols = [

View on GitHub (pinned to fe841f959e)