Skip to content

Commit fea52e4

Browse files
authored
feat(pkg-py): Add a new .data module (#124)
* feat(pkg-py): Add a new data module * Fix for old versions of Python * Avoid variable shadowing
1 parent f5e068b commit fea52e4

File tree

17 files changed

+227
-49
lines changed

17 files changed

+227
-49
lines changed

pkg-py/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1919

2020
* The current SQL query and title can now be programmatically set through the `.sql()` and `.title()` methods of `QueryChat()`. (#98, #101)
2121

22+
* New `querychat.data` module provides sample datasets (`titanic()` and `tips()`) to make it easier to get started without external dependencies. (#118)
23+
2224
* Added a `.generate_greeting()` method to help you create a greeting message for your querychat bot. (#87)
2325

2426
* Added `querychat_reset_dashboard()` tool for easily resetting the dashboard filters when asked by the user. (#81)

pkg-py/docs/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1919

2020
* The current SQL query and title can now be programmatically set through the `.sql()` and `.title()` methods of `QueryChat()`. (#98, #101)
2121

22+
* New `querychat.data` module provides sample datasets (`titanic()` and `tips()`) to make it easier to get started without external dependencies. (#118)
23+
2224
* Added a `.generate_greeting()` method to help you create a greeting message for your querychat bot. (#87)
2325

2426
* Added `querychat_reset_dashboard()` tool for easily resetting the dashboard filters when asked by the user. (#81)

pkg-py/docs/build.qmd

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -181,14 +181,13 @@ Thanks to Shiny's support for [Jupyter Widgets](https://shiny.posit.co/py/docs/j
181181
```python
182182
import plotly.express as px
183183

184-
from seaborn import load_dataset
185184
from shiny.express import render, ui
186185
from shinywidgets import render_plotly
187186

188187
from querychat.express import QueryChat
188+
from querychat.data import titanic
189189

190-
titanic = load_dataset("titanic")
191-
qc = QueryChat(titanic, "titanic")
190+
qc = QueryChat(titanic(), "titanic")
192191
qc.sidebar()
193192

194193
with ui.layout_columns():
@@ -223,12 +222,11 @@ A more useful, but slightly more involved example like the one below might incor
223222
from shiny.express import render, ui
224223
from shinywidgets import render_plotly
225224
from querychat.express import QueryChat
226-
from seaborn import load_dataset
225+
from querychat.data import titanic
227226
from faicons import icon_svg
228227
import plotly.express as px
229228

230-
titanic = load_dataset("titanic")
231-
qc = QueryChat(titanic, "titanic")
229+
qc = QueryChat(titanic(), "titanic")
232230
qc.sidebar()
233231

234232
with ui.layout_column_wrap(fill=False):
@@ -356,11 +354,11 @@ You can use multiple QueryChat instances in a single app to explore different da
356354
from seaborn import load_dataset
357355
from shiny.express import render, ui
358356
from querychat.express import QueryChat
357+
from querychat.data import titanic
359358

360-
titanic = load_dataset("titanic")
361359
penguins = load_dataset("penguins")
362360

363-
qc_titanic = QueryChat(titanic, "titanic")
361+
qc_titanic = QueryChat(titanic(), "titanic")
364362
qc_penguins = QueryChat(penguins, "penguins")
365363

366364
with ui.sidebar():
@@ -396,15 +394,12 @@ Here's a complete example bringing together multiple concepts - a Titanic surviv
396394
```python
397395
from shiny.express import render, ui
398396
from querychat.express import QueryChat
399-
from seaborn import load_dataset
397+
from querychat.data import titanic
400398
import plotly.express as px
401399

402-
# Load data
403-
titanic = load_dataset("titanic")
404-
405400
# Create QueryChat
406401
qc = QueryChat(
407-
titanic,
402+
titanic(),
408403
"titanic",
409404
data_description="Titanic passenger data with survival outcomes",
410405
)

pkg-py/docs/context.qmd

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,9 @@ For full visibility into the full system prompt that Querychat generates for the
1212

1313
```python
1414
from querychat import QueryChat
15-
from seaborn import load_dataset
15+
from querychat.data import titanic
1616

17-
titanic = load_dataset("titanic")
18-
19-
qc = QueryChat(titanic, "titanic")
17+
qc = QueryChat(titanic(), "titanic")
2018
print(qc.system_prompt)
2119
```
2220

pkg-py/docs/data-sources.qmd

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -160,12 +160,10 @@ Or, if you have a pandas DataFrame, you can create the DuckDB database like so:
160160
```{.python filename="create-duckdb-from-pandas.py"}
161161
import duckdb
162162
import pandas as pd
163-
164-
from seaborn import load_dataset
165-
titanic = load_dataset("titanic")
163+
from querychat.data import titanic
166164
167165
conn = duckdb.connect("my_database.duckdb")
168-
conn.register('titanic_df', titanic)
166+
conn.register('titanic_df', titanic())
169167
conn.execute("""
170168
CREATE TABLE titanic AS
171169
SELECT * FROM titanic_df

pkg-py/docs/index.qmd

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,10 @@ The quickest way to start chatting is to call the `.app()` method, which returns
4040

4141

4242
```{.python filename="titanic-app.py"}
43-
from seaborn import load_dataset
4443
from querychat import QueryChat
44+
from querychat.data import titanic
4545
46-
titanic = load_dataset("titanic")
47-
qc = QueryChat(titanic, "titanic", client="openai/gpt-4.1")
46+
qc = QueryChat(titanic(), "titanic", client="openai/gpt-4.1")
4847
app = qc.app()
4948
```
5049

pkg-py/docs/models.qmd

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,10 @@ To use a particular model, pass a `"{provider}/{model}"` string to the `client`
1010

1111
```python
1212
from querychat import QueryChat
13-
from seaborn import load_dataset
14-
titanic = load_dataset("titanic")
13+
from querychat.data import titanic
1514

1615
qc = QueryChat(
17-
titanic,
16+
titanic(),
1817
"titanic",
1918
client="anthropic/claude-sonnet-4-5"
2019
)

pkg-py/docs/tools.qmd

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,9 @@ Here's a basic example of this tool in action with the `.app()` method. Notice h
2323

2424
```{.python filename="titanic-app.py"}
2525
from querychat import QueryChat
26-
from seaborn import load_dataset
26+
from querychat.data import titanic
2727
28-
titanic = load_dataset("titanic")
29-
qc = QueryChat(titanic, "titanic")
28+
qc = QueryChat(titanic(), "titanic")
3029
app = qc.app()
3130
```
3231

@@ -46,10 +45,9 @@ Here's an example of it in action:
4645

4746
```{.python filename="titanic-app.py"}
4847
from querychat import QueryChat
49-
from seaborn import load_dataset
48+
from querychat.data import titanic
5049
51-
titanic = load_dataset("titanic")
52-
qc = QueryChat(titanic, "titanic")
50+
qc = QueryChat(titanic(), "titanic")
5351
app = qc.app()
5452
```
5553

pkg-py/examples/01-hello-app.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
from seaborn import load_dataset
21
from querychat import QueryChat
2+
from querychat.data import titanic
33

4-
titanic = load_dataset("titanic")
5-
qc = QueryChat(titanic, "titanic")
4+
qc = QueryChat(titanic(), "titanic")
65
app = qc.app()

pkg-py/examples/02-prompt-app.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
11

22
from pathlib import Path
3-
from seaborn import load_dataset
43
from querychat import QueryChat
5-
6-
titanic = load_dataset("titanic")
4+
from querychat.data import titanic
75

86
greeting = Path(__file__).parent / "greeting.md"
97
data_desc = Path(__file__).parent / "data_description.md"
108

119
qc = QueryChat(
12-
titanic,
10+
titanic(),
1311
"titanic",
1412
greeting=greeting,
1513
data_description=data_desc,

0 commit comments

Comments
 (0)