Skip to content

AttributeError when computing length of DuckDB-produced lazy Polars frame #20094

@Hunterlige

Description

@Hunterlige

What happens?

Calling .pl(lazy=True) on a DuckDB query result and then using Polars operations (such as getting the len of the LazyFrame) cause a polars.exceptions.ComputeError.

polars.exceptions.ComputeError: caught exception during execution of a Python source, exception: AttributeError: 'NoneType' object has no attribute 'fetch_arrow_reader'

Interestingly, this error only happens when using con = duckdb.connect(), using duckdb.sql like described in https://duckdb.org/docs/stable/guides/python/polars#duckdb-to-polars works fine

To Reproduce

import duckdb
import polars as pl

con = duckdb.connect()

results = con.execute("""
        SELECT 1 AS id, 'banana' AS fruit
    """).pl(lazy=True)

print(results.select(pl.len()).collect().item())

OS:

iOS

DuckDB Version:

1.4.2

DuckDB Client:

Python

Hardware:

No response

Full Name:

Denis Lusson

Affiliation:

Corvic AI

Did you include all relevant configuration (e.g., CPU architecture, Linux distribution) to reproduce the issue?

  • Yes, I have

Did you include all code required to reproduce the issue?

  • Yes, I have

Did you include all relevant data sets for reproducing the issue?

Not applicable - the reproduction does not require a data set

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions