Replies: 4 comments 10 replies
-
Yes that is certainly possible, we would have to figure out how to read polars data frames. Is there some documentation available on how they are stored internally? |
Beta Was this translation helpful? Give feedback.
-
If its also NumPy array at the bottom it should be doable |
Beta Was this translation helpful? Give feedback.
-
Their Python API has a to_arrow method Collect the underlying arrow arrays in an Arrow Table. This operation is mostly zero copy. Data types that do copy: |
Beta Was this translation helpful? Give feedback.
-
Here is a boilerplate example of using Apache Arrow as the bridge between Polars and DuckDB. This is a key value of Arrow for us - we don't have to build a connector to every other library. We can just use the high speed of Arrow and DuckDB's ability to read it directly for fast workflows on many other libraries! Please let us know how this goes! import duckdb
import polars as pl
df = pl.DataFrame(
{
"A": [1, 2, 3, 4, 5],
"fruits": ["banana", "banana", "apple", "apple", "banana"],
"B": [5, 4, 3, 2, 1],
"cars": ["beetle", "audi", "beetle", "beetle", "beetle"],
}
)
# Convert from Polars to Arrow
# (this handles the non-Arrow CategoricalType data type)
# Aside from CategoricalType columns, it is zero copy so should be performant
arrow_from_polars = df.to_arrow()
duckdb_conn = duckdb.connect(':memory:')
# Once the Arrow table is in Python's local variables, DuckDB can read from it just by using the variable name!
duckdb_result_as_arrow = duckdb_conn.execute("""
select
*
,'any_new_column_etc.' as test_col
from arrow_from_polars --DuckDB can deduce that this is an Arrow table and scan it
""").fetch_arrow_table()
print(duckdb_result_as_arrow) |
Beta Was this translation helpful? Give feedback.
-
Hello,
I am aware that DuckDB Python library works with pandas data frames as described here:
https://duckdb.org/2021/05/14/sql-on-pandas.html
Would it be possible to do the same with polars data frames without the need to convert these to pandas df?
Best wishes,
Darek Kedra
Beta Was this translation helpful? Give feedback.
All reactions