Feature Request: Remove PyArrow requirement for Polars import/export #132
Replies: 2 comments 4 replies
-
|
Yah, polars_io.py relies on fetch_arrow_stream in all paths, but, it looks like the method in 10716 still works which is neat: import duckdb
import polars as pl
class ArrowStream:
def __init__(self, obj):
self.obj = obj
def __arrow_c_stream__(self, requested_schema=None):
return self.obj.__arrow_c_stream__(requested_schema=requested_schema)
df = pl.DataFrame({"a": [1, 2, 3, 4]})
stream = ArrowStream(df)
con = duckdb.connect()
# Reading from the wrapper
sql = "SELECT * FROM stream"
con.query(sql)Perhaps that could be used as a fallback for when pyarrow isn't installed? |
Beta Was this translation helpful? Give feedback.
-
|
Oh, and for the reverse, pyrelation.cpp would need a small change to construct the Polars dataframe directly, instead of going through PolarsDataFrame DuckDBPyRelation::ToPolars(idx_t batch_size, bool lazy) {
if (!lazy) {
auto polars_module = pybind11::module_::import("polars");
return py::cast<PolarsDataFrame>(polars_module.attr("DataFrame")(*this));
}This would allow the following without pyarrow installed: import duckdb
duckdb.execute("select * from range(1)").pl();AlternativelyJust create the dataframe in Polars from the relation, no pyarrow needed. import duckdb
import polars as pl
rel = duckdb.sql("select * from range(10)")
df = pl.DataFrame(rel)* And a similar change to the lazy path, and probably polars_io.py ** happy to open a PR |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Now that support for the Arrow PyCapsule Interface has been implemented in duckdb/duckdb#10716, it's possible to exchange Arrow data with Polars without PyArrow installed. However, this doesn't work in practice because DuckDB checks if the input is a Polars object before checking for existence of the Arrow PyCapsule Interface. So reading Polars data works without pyarrow only if you hide the fact that it's a
polars.DataFrame.Feature request lifted from discussion here: duckdb/duckdb#13827
Beta Was this translation helpful? Give feedback.
All reactions