pola-rs/polars · error · TypeError
from_lazyframe.resolver(): expected instance of…
Error message
from_lazyframe.resolver(): expected instance of LazyFrameResolver, got: {resolver = } {type(resolver) = } What it means
LazyFrame.from_lazyframe_resolver requires a LazyFrameResolver instance; any other object (raw LazyFrame, wrapper, mock) is rejected with a TypeError that echoes the value and its type. This guards the Rust-side PyLazyFrame.from_lazyframe_resolver FFI boundary.
Solutions
- Pass a LazyFrameResolver instance (construct/wrap your LazyFrame in one first).
- Use LazyFrame.from_lazyframe if you actually have a plain LazyFrame.
- Add an isinstance check before calling to fail early with a clearer message.
Example fix
// before LazyFrame.from_lazyframe_resolver(lf) // after LazyFrame.from_lazyframe_resolver(LazyFrameResolver(lf))
Defensive patterns
Strategy: type-guard
Validate before calling
if not isinstance(resolver, LazyFrameResolver):
raise TypeError(f'expected LazyFrameResolver, got {type(resolver).__name__}') Type guard
def is_resolver(obj: object) -> bool:
return isinstance(obj, LazyFrameResolver) Try / catch
try:
out = LazyFrame.from_lazyframe_resolver(x)
except TypeError as e:
if 'LazyFrameResolver' in str(e):
out = LazyFrame.from_lazyframe(x) if isinstance(x, LazyFrame) else None
else:
raise Prevention
- Distinguish from_lazyframe (plain LazyFrame) from from_lazyframe_resolver (LazyFrameResolver).
- Ensure test doubles subclass LazyFrameResolver if they reach this API.
When it happens
Trigger: Calling LazyFrame.from_lazyframe_resolver(lf) with a LazyFrame instead of a LazyFrameResolver, or with an object that wraps/duck-types one.
Common situations: Confusing from_lazyframe with from_lazyframe_resolver; migrating code between the two constructors; test doubles that don't subclass LazyFrameResolver.
Related errors
- `arctan2` expected a `str` or `Expr` got a
- `arctan2` expected a `str` or `Expr` got a
- can only convert date/datetime to NaiveDateTime
- can only convert date/datetime to NaiveTime
- can't convert to Decimal
AI-assisted analysis of pola-rs/polars@fe841f959e (2026-09-18).
Data as JSON: /api/errors/55aa78868f8cb4cb.
Report an issue: GitHub.
Appendix: source
Thrown at py-polars/src/polars/lazyframe/frame.py:404
.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 fe841f959e)