-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support DuckDBPyRelation kernel computations (#37)
- Loading branch information
1 parent
a700b38
commit 30a9ed4
Showing
7 changed files
with
196 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -165,3 +165,6 @@ cython_debug/ | |
#.idea/ | ||
script.* | ||
tmp_graphic_walker.json | ||
tmp.db | ||
tmp.ibis.db | ||
tmp.db.wal |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
from typing import Any, Dict, List | ||
|
||
import duckdb | ||
import pandas as pd | ||
import pytest | ||
|
||
|
||
class Connector: | ||
def __init__(self, relation): | ||
self.relation = relation | ||
self.view_sql = "SELECT * FROM __relation" | ||
|
||
def query_datas(self, sql: str) -> List[Dict[str, Any]]: | ||
__relation = self.relation | ||
|
||
result = self.relation.query("__relation", sql).fetchall() | ||
columns = self.relation.query("__relation", sql).columns | ||
records = [dict(zip(columns, row)) for row in result] | ||
return records | ||
|
||
@property | ||
def dialect_name(self) -> str: | ||
return "duckdb" | ||
|
||
|
||
@pytest.fixture(params=["in-memory", "persistent"]) | ||
def con(request, tmp_path): | ||
if request.param == "in-memory": | ||
database = ":memory:" | ||
else: | ||
database = (tmp_path / "tmp.db").as_posix() | ||
con = duckdb.connect(database) | ||
con.execute("CREATE TABLE df_pandas (a INTEGER)") | ||
con.execute("INSERT INTO df_pandas VALUES (1), (2), (3)") | ||
return con | ||
|
||
|
||
@pytest.fixture | ||
def data(con): | ||
return con.sql("SELECT * FROM df_pandas") | ||
|
||
|
||
def test_connector_simple_works(): | ||
df_pandas = pd.DataFrame({"a": [1, 2, 3]}) | ||
data = duckdb.sql("SELECT * FROM df_pandas") | ||
connector = Connector(data) | ||
assert connector.dialect_name == "duckdb" | ||
assert connector.query_datas("SELECT * FROM __relation") == [ | ||
{"a": 1}, | ||
{"a": 2}, | ||
{"a": 3}, | ||
] | ||
|
||
|
||
def test_connector_advanced_which_does_not_work(data): | ||
connector = Connector(data) | ||
assert connector.dialect_name == "duckdb" | ||
assert connector.query_datas("SELECT * FROM __relation") == [ | ||
{"a": 1}, | ||
{"a": 2}, | ||
{"a": 3}, | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,9 @@ | ||
import dask.dataframe as dd | ||
import duckdb | ||
import pytest | ||
|
||
from panel_gwalker._gwalker import get_data_parser | ||
|
||
|
||
def test_get_data_parser(data): | ||
if isinstance(data, (dd.DataFrame, duckdb.duckdb.DuckDBPyRelation)): | ||
pytest.xfail(f"Unsupported data type: {type(data)}") | ||
|
||
if str(type(data)) == "<class 'dask_expr._collection.DataFrame'>": | ||
pytest.xfail("Dask DataFrame is not supported yet") | ||
assert get_data_parser(data, [], False, False, {}) |