Skip to content

Instantly share code, notes, and snippets.

@ianmcook
Created February 14, 2024 16:21
Show Gist options
  • Save ianmcook/06f6ca3b5a5b1d64ba0fb03ff053a3ef to your computer and use it in GitHub Desktop.
Save ianmcook/06f6ca3b5a5b1d64ba0fb03ff053a3ef to your computer and use it in GitHub Desktop.
Different ways to create a DuckDB table from Ibis
import pandas as pd
import ibis
# Different ways to create a DuckDB table from Ibis
# ibis.memtable(...): ephemeral, all in-memory, stored as a view inside duckdb, removed when the session ends
# ibis.memtable(...).cache(): ephemeral, stored as temporary table in the duckdb database, removed when the session ends, expression is cached for the lifetime of the session
# con.create_table(..., temp=True): ephemeral, stored as temporary table in the duckdb database, removed when the session ends, expression is NOT cached for the lifetime of the session
# con.create_table(...): persistent, across sessions (assuming you're not using an in-memory connection)
# Also see https://github.com/ibis-project/ibis/issues/6007
# create example data in a pandas DataFrame
df = pd.DataFrame(data={'fruit': ['apple', 'apple', 'apple', 'orange', 'orange', 'orange'],
'variety': ['gala', 'honeycrisp', 'fuji', 'navel', 'valencia', 'cara cara'],
'weight': [134.2 , 158.6, None, 142.1, 96.7, None]})
t = ibis.memtable(df)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment