querychat 0.2.1__tar.gz → 0.2.2__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {querychat-0.2.1 → querychat-0.2.2}/PKG-INFO +1 -1
- {querychat-0.2.1 → querychat-0.2.2}/pkg-py/src/querychat/datasource.py +16 -7
- {querychat-0.2.1 → querychat-0.2.2}/pkg-py/src/querychat/querychat.py +3 -6
- {querychat-0.2.1 → querychat-0.2.2}/pyproject.toml +2 -1
- {querychat-0.2.1 → querychat-0.2.2}/.gitignore +0 -0
- {querychat-0.2.1 → querychat-0.2.2}/LICENSE.md +0 -0
- {querychat-0.2.1 → querychat-0.2.2}/pkg-py/LICENSE +0 -0
- {querychat-0.2.1 → querychat-0.2.2}/pkg-py/README.md +0 -0
- {querychat-0.2.1 → querychat-0.2.2}/pkg-py/src/querychat/__init__.py +0 -0
- {querychat-0.2.1 → querychat-0.2.2}/pkg-py/src/querychat/_utils.py +0 -0
- {querychat-0.2.1 → querychat-0.2.2}/pkg-py/src/querychat/prompt/prompt.md +0 -0
- {querychat-0.2.1 → querychat-0.2.2}/pkg-py/src/querychat/static/css/styles.css +0 -0
|
@@ -3,12 +3,13 @@ from __future__ import annotations
|
|
|
3
3
|
from typing import TYPE_CHECKING, ClassVar, Protocol
|
|
4
4
|
|
|
5
5
|
import duckdb
|
|
6
|
-
import narwhals as nw
|
|
6
|
+
import narwhals.stable.v1 as nw
|
|
7
7
|
import pandas as pd
|
|
8
8
|
from sqlalchemy import inspect, text
|
|
9
9
|
from sqlalchemy.sql import sqltypes
|
|
10
10
|
|
|
11
11
|
if TYPE_CHECKING:
|
|
12
|
+
from narwhals.stable.v1.typing import IntoFrame
|
|
12
13
|
from sqlalchemy.engine import Connection, Engine
|
|
13
14
|
|
|
14
15
|
|
|
@@ -58,8 +59,9 @@ class DataFrameSource:
|
|
|
58
59
|
"""A DataSource implementation that wraps a pandas DataFrame using DuckDB."""
|
|
59
60
|
|
|
60
61
|
db_engine: ClassVar[str] = "DuckDB"
|
|
62
|
+
_df: nw.DataFrame | nw.LazyFrame
|
|
61
63
|
|
|
62
|
-
def __init__(self, df:
|
|
64
|
+
def __init__(self, df: IntoFrame, table_name: str):
|
|
63
65
|
"""
|
|
64
66
|
Initialize with a pandas DataFrame.
|
|
65
67
|
|
|
@@ -69,9 +71,10 @@ class DataFrameSource:
|
|
|
69
71
|
|
|
70
72
|
"""
|
|
71
73
|
self._conn = duckdb.connect(database=":memory:")
|
|
72
|
-
self._df = df
|
|
74
|
+
self._df = nw.from_native(df)
|
|
73
75
|
self._table_name = table_name
|
|
74
|
-
|
|
76
|
+
# TODO(@gadenbuie): If the data frame is already SQL-backed, maybe we shouldn't be making a new copy here.
|
|
77
|
+
self._conn.register(table_name, self._df.lazy().collect().to_pandas())
|
|
75
78
|
|
|
76
79
|
def get_schema(self, *, categorical_threshold: int) -> str:
|
|
77
80
|
"""
|
|
@@ -86,10 +89,15 @@ class DataFrameSource:
|
|
|
86
89
|
String describing the schema
|
|
87
90
|
|
|
88
91
|
"""
|
|
89
|
-
ndf = nw.from_native(self._df)
|
|
90
|
-
|
|
91
92
|
schema = [f"Table: {self._table_name}", "Columns:"]
|
|
92
93
|
|
|
94
|
+
# Ensure we're working with a DataFrame, not a LazyFrame
|
|
95
|
+
ndf = (
|
|
96
|
+
self._df.head(10).collect()
|
|
97
|
+
if isinstance(self._df, nw.LazyFrame)
|
|
98
|
+
else self._df
|
|
99
|
+
)
|
|
100
|
+
|
|
93
101
|
for column in ndf.columns:
|
|
94
102
|
# Map pandas dtypes to SQL-like types
|
|
95
103
|
dtype = ndf[column].dtype
|
|
@@ -149,7 +157,8 @@ class DataFrameSource:
|
|
|
149
157
|
The complete dataset as a pandas DataFrame
|
|
150
158
|
|
|
151
159
|
"""
|
|
152
|
-
return self._df
|
|
160
|
+
# TODO(@gadenbuie): This should just return `self._df` and not a pandas DataFrame
|
|
161
|
+
return self._df.lazy().collect().to_pandas()
|
|
153
162
|
|
|
154
163
|
|
|
155
164
|
class SQLAlchemySource:
|
|
@@ -414,15 +414,12 @@ def init(
|
|
|
414
414
|
data_source_obj: DataSource
|
|
415
415
|
if isinstance(data_source, sqlalchemy.Engine):
|
|
416
416
|
data_source_obj = SQLAlchemySource(data_source, table_name)
|
|
417
|
-
|
|
417
|
+
else:
|
|
418
418
|
data_source_obj = DataFrameSource(
|
|
419
|
-
|
|
419
|
+
data_source,
|
|
420
420
|
table_name,
|
|
421
421
|
)
|
|
422
|
-
|
|
423
|
-
raise TypeError(
|
|
424
|
-
"`data_source` must be a Narwhals DataFrame or LazyFrame, or a SQLAlchemy Engine",
|
|
425
|
-
)
|
|
422
|
+
|
|
426
423
|
# Process greeting
|
|
427
424
|
if greeting is None:
|
|
428
425
|
print(
|
|
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "querychat"
|
|
7
|
-
version = "0.2.
|
|
7
|
+
version = "0.2.2"
|
|
8
8
|
description = "Chat with your data using natural language"
|
|
9
9
|
readme = "pkg-py/README.md"
|
|
10
10
|
requires-python = ">=3.9"
|
|
@@ -124,6 +124,7 @@ extend-ignore = [
|
|
|
124
124
|
"D107", # Missing docstring in __init__
|
|
125
125
|
"D205", # 1 blank line required between summary line and description
|
|
126
126
|
"UP045", # Use `X | NULL` for type annotations, not `Optional[X]`
|
|
127
|
+
"TD003", # TODO doesn't need to have an issue link
|
|
127
128
|
]
|
|
128
129
|
extend-select = [
|
|
129
130
|
# "C90", # C90; mccabe: https://docs.astral.sh/ruff/rules/complex-structure/
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|