pola-rs/polars · error · ValueError

unrecognised frame type

Error message

unrecognised frame type: {qualified_type_name(obj)}

What it means

SQLContext.register (via _ensure_lazyframe) accepts LazyFrames, DataFrames, and a known set of external objects (pycapsule providers, pyarrow Table/RecordBatch, pandas, etc.). Anything else raises ValueError because it cannot be converted to a LazyFrame for registration.

Solutions

  1. Convert explicitly first: ctx.register('t', pl.DataFrame(obj)) or pl.from_arrow(obj).lazy().
  2. For pandas, use pl.from_pandas(df).lazy().
  3. If it's already a LazyFrame, register it directly; verify with isinstance(obj, pl.LazyFrame).

Example fix

# before
ctx.register('tbl', numpy_array)  # ValueError

# after
ctx.register('tbl', pl.DataFrame(numpy_array).lazy())
Defensive patterns

Strategy: type-guard

Validate before calling

if not isinstance(obj, (pl.LazyFrame, pl.DataFrame, pl.Series)) and not hasattr(obj, '__arrow_c_stream__'):
    obj = pl.DataFrame(obj).lazy()

Type guard

def is_registrable(obj) -> bool:
    return isinstance(obj, (pl.LazyFrame, pl.DataFrame)) or hasattr(obj, '__arrow_c_stream__')

Try / catch

try:
    ctx.register('t', obj)
except ValueError:
    ctx.register('t', pl.from_arrow(obj).lazy())

Prevention

When it happens

Trigger: ctx.register('t', some_numpy_array), registering a polars Series, a pyarrow RecordBatchReader of unsupported kind, a plain list, or an arbitrary Python object.

Common situations: Passing a pandas DataFrame after a refactor removed the pandas extra; registering a Spark/DuckDB relation hoping for auto-conversion; accidentally registering the result of df.to_arrow() stored as a batch reader.

Understand the failure class

Background: "is not a compatible type" / "cannot merge" errors: when a value's type doesn't match what the library requires — this error's family across 65 libraries.

Related errors


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

Appendix: source

Thrown at py-polars/src/polars/sql/context.py:77


def _ensure_lazyframe(obj: Any) -> LazyFrame:
    """Return LazyFrame from compatible input."""
    if isinstance(obj, (DataFrame, LazyFrame)):
        return obj.lazy()
    elif isinstance(obj, Series):
        return obj.to_frame().lazy()
    elif _check_for_pandas(obj) and isinstance(obj, (pd.DataFrame, pd.Series)):
        if isinstance(frame := from_pandas(obj), Series):
            frame = frame.to_frame()
        return frame.lazy()
    elif is_pycapsule(obj) or (
        _check_for_pyarrow(obj) and isinstance(obj, (pa.Table, pa.RecordBatch))
    ):
        return DataFrame(obj).lazy()  # type: ignore[union-attr]
    else:
        msg = f"unrecognised frame type: {qualified_type_name(obj)}"
        raise ValueError(msg)


def _get_frame_locals(
    *,
    all_compatible: bool,
    n_objects: int | None = None,
    named: str | Collection[str] | Callable[[str], bool] | None = None,
) -> dict[str, Any]:
    """Return compatible frame objects from the local stack."""
    of_type = _compatible_frame if all_compatible else (DataFrame, LazyFrame, Series)
    return _get_stack_locals(of_type=of_type, n_objects=n_objects, named=named)  # type: ignore[arg-type]


class SQLContext(Generic[FrameType]):
    """
    Run SQL queries against DataFrame, LazyFrame, and Series data.

    .. warning::

View on GitHub (pinned to fe841f959e)