pola-rs/polars · error · TypeError
from_lazyframe.resolver(): expected instance of LazyFrameRes
Error message
from_lazyframe.resolver(): expected instance of LazyFrameResolver, got: {resolver = } {type(resolver) = } What it means
LazyFrame.from_lazyframe(...) with a resolver argument requires `resolver` to be an actual LazyFrameResolver instance. Any other object (None, a string, a callable, a wrapped proxy) raises this TypeError, echoing the value and its type to help identify what was passed.
Source
Thrown at py-polars/src/polars/lazyframe/frame.py:393
.lazy()
._ldf
)
@classmethod
def from_lazyframe_resolver(cls, resolver: LazyFrameResolver) -> LazyFrame:
"""
Create a LazyFrame from a LazyFrame resolver.
.. warning::
This functionality is considered **unstable**. It may be changed
at any point without it being considered a breaking change.
"""
if not isinstance(resolver, LazyFrameResolver):
msg = (
"from_lazyframe.resolver(): expected instance of LazyFrameResolver, "
f"got: {resolver = } {type(resolver) = }"
)
raise TypeError(msg)
return wrap_ldf(PyLazyFrame.from_lazyframe_resolver(resolver))
@classmethod
def _from_pyldf(cls, ldf: PyLazyFrame) -> LazyFrame:
self = cls.__new__(cls)
self._ldf = ldf
return self
def _with_height_column(self) -> LazyFrame:
"""Add a private dummy column that preserves the input height."""
return self.with_columns(F.lit({}, dtype=Struct({})).alias(_HEIGHT_COLUMN))
def _drop_height_column(self) -> LazyFrame:
"""Drop the dummy column added by `_with_height_column()`."""
return self.drop(_HEIGHT_COLUMN)
def _height_preserving(self, op: Callable[[LazyFrame], LazyFrame]) -> LazyFrame:View on GitHub (pinned to 68506541d2)
Solutions
- Construct and pass a LazyFrameResolver instance (e.g. LazyFrameResolver(...) or the factory that produces one), not a class or callable.
- Check `isinstance(resolver, LazyFrameResolver)` before the call; inspect the printed type(resolver) in the message to see what you actually passed.
- Ensure a single polars installation is imported (no duplicated/aliased polars packages) so the isinstance check matches.
Example fix
// before lf2 = LazyFrame.from_lazyframe(lf, resolver=my_resolver_fn) // after resolver = LazyFrameResolver(my_resolver_fn) lf2 = LazyFrame.from_lazyframe(lf, resolver=resolver)
Defensive patterns
Strategy: type-guard
Validate before calling
from polars.lazyframe.frame import LazyFrameResolver
if not isinstance(resolver, LazyFrameResolver):
raise TypeError(f"resolver must be LazyFrameResolver, got {type(resolver)}") Type guard
def is_lazyframe_resolver(resolver) -> bool:
from polars.lazyframe.frame import LazyFrameResolver
return isinstance(resolver, LazyFrameResolver) Try / catch
try:
out = LazyFrame.from_lazyframe(lf, resolver=resolver)
except TypeError as e:
if "expected instance of LazyFrameResolver" in str(e):
resolver = LazyFrameResolver(resolver)
out = LazyFrame.from_lazyframe(lf, resolver=resolver)
else:
raise Prevention
- Pass instances, not classes or callables
- Import LazyFrameResolver from a single canonical module path
- Pin one polars version to avoid isinstance failing across duplicate installs
- Assert resolver type in tests around from_lazyframe
When it happens
Trigger: Calling LazyFrame.from_lazyframe(lf, resolver=<x>) where x is not an instance of polars.lazyframe.frame.LazyFrameResolver — e.g. passing a plain function, a string name of a resolver, None, or a resolver class instead of an instance.
Common situations: Confusing the resolver class with an instance; passing an older-style callback; mixing polars versions where the resolver type lives in a different module so isinstance fails across duplicate imports.
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
- list.to_struct() got a str instead of a list. hint: pass ['{
- expected object supporting the PyCapsule Interface, got {qua
- 'join_where' requires at least one predicate
- arr.to_struct() got a str instead of a list. hint: pass ['{f
- Map requires a key and a value type, e.g. `pl.Map(pl.String,
AI-assisted analysis of pola-rs/polars@68506541d2 (2026-09-10).
Data as JSON: /api/errors/55aa78868f8cb4cb.
Report an issue: GitHub.