types.DataFrameSource
DataFrameSource(df, table_name)
A DataSource implementation that wraps a DataFrame using DuckDB.
Methods
cleanup
types.DataFrameSource.cleanup()
Close the DuckDB connection.
execute_query
types.DataFrameSource.execute_query(query)
Execute query using DuckDB.
Uses polars if available, otherwise falls back to pandas.
Parameters
| query |
str |
SQL query to execute |
required |
Returns
|
nw.DataFrame |
Query results as narwhals DataFrame |
Raises
|
UnsafeQueryError |
If the query starts with a disallowed SQL operation |
get_data
types.DataFrameSource.get_data()
Return the unfiltered data as a DataFrame.
Returns
|
nw.DataFrame |
The complete dataset as a narwhals DataFrame |
get_db_type
types.DataFrameSource.get_db_type()
Get the database type.
get_schema
types.DataFrameSource.get_schema(categorical_threshold)
Generate schema information from DataFrame.
Parameters
| categorical_threshold |
int |
Maximum number of unique values for a text column to be considered categorical |
required |
Returns
|
str |
String describing the schema |
test_query
types.DataFrameSource.test_query(query, *, require_all_columns=False)
Test query by fetching only one row.
Parameters
| query |
str |
SQL query to test |
required |
| require_all_columns |
bool |
If True, validates that result includes all original table columns |
False |
Returns
|
nw.DataFrame |
Query results with at most one row |
Raises
|
UnsafeQueryError |
If the query starts with a disallowed SQL operation |
|
MissingColumnsError |
If require_all_columns is True and result is missing required columns |