Skip to content

Commit a49e243

Browse files
authored
py/v0.2.0 (#73)
* v0.2.0 * chore: update maintainer * fix(pkg-py): handle possibly lazy data frames * chore: add tests to `make py-check` * ci(pkg-py): Check tests before release
1 parent 692ae16 commit a49e243

File tree

5 files changed

+42
-15
lines changed

5 files changed

+42
-15
lines changed

.github/workflows/py-release.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,9 @@ jobs:
3333
- name: 📦 Install the project
3434
run: uv sync --python ${{ env.PYTHON_VERSION }} --all-extras --all-groups
3535

36-
# - name: 🧪 Check tests
37-
# run: make py-check-tests
36+
- name: 🧪 Check tests
37+
run: make py-check-tests
38+
3839
- name: 📝 Check types
3940
working-directory: ./pkg-py
4041
run: make py-check-types

Makefile

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,11 +111,10 @@ r-docs-preview: ## [r] Build R docs
111111

112112
.PHONY: py-setup
113113
py-setup: ## [py] Setup python environment
114-
uv sync --all-extras --all-groups
114+
uv sync --all-extras --all-groups --upgrade
115115

116116
.PHONY: py-check
117-
# py-check: py-check-format py-check-types py-check-tests ## [py] Run python checks
118-
py-check: py-check-format py-check-types ## [py] Run python checks
117+
py-check: py-check-format py-check-types py-check-tests ## [py] Run python checks
119118

120119
.PHONY: py-check-tox
121120
py-check-tox: ## [py] Run python 3.9 - 3.12 checks with tox

pkg-py/CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8-
## [UNRELEASED]
8+
## [0.2.0] - 2025-09-02
99

1010
* `querychat.init()` now accepts a `client` argument, replacing the previous `create_chat_callback` argument. (#60)
1111

pkg-py/src/querychat/querychat.py

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,14 @@
77
import warnings
88
from dataclasses import dataclass
99
from pathlib import Path
10-
from typing import TYPE_CHECKING, Any, Callable, Optional, Protocol, Union
10+
from typing import (
11+
TYPE_CHECKING,
12+
Any,
13+
Callable,
14+
Optional,
15+
Protocol,
16+
Union,
17+
)
1118

1219
import chatlas
1320
import chevron
@@ -217,8 +224,16 @@ def df_to_html(df: IntoFrame, maxrows: int = 5) -> str:
217224
HTML string representation of the table
218225
219226
"""
220-
ndf = nw.from_native(df)
221-
df_short = nw.from_native(df).head(maxrows)
227+
df_short: nw.DataFrame[Any]
228+
229+
if isinstance(df, nw.LazyFrame):
230+
ndf_eager = df.collect()
231+
df_short = df.head(maxrows).collect()
232+
elif isinstance(df, nw.DataFrame):
233+
ndf_eager = df
234+
df_short = df.head(maxrows)
235+
else:
236+
raise TypeError("df must be a Narwhals DataFrame or LazyFrame")
222237

223238
# Generate HTML table
224239
table_html = df_short.to_pandas().to_html(
@@ -227,9 +242,9 @@ def df_to_html(df: IntoFrame, maxrows: int = 5) -> str:
227242
)
228243

229244
# Add note about truncated rows if needed
230-
if len(df_short) != len(ndf):
245+
if len(df_short) != len(ndf_eager):
231246
rows_notice = (
232-
f"\n\n(Showing only the first {maxrows} rows out of {len(ndf)}.)\n"
247+
f"\n\n(Showing only the first {maxrows} rows out of {len(ndf_eager)}.)\n"
233248
)
234249
else:
235250
rows_notice = ""
@@ -400,11 +415,15 @@ def init(
400415
data_source_obj: DataSource
401416
if isinstance(data_source, sqlalchemy.Engine):
402417
data_source_obj = SQLAlchemySource(data_source, table_name)
403-
else:
418+
elif isinstance(data_source, (nw.DataFrame, nw.LazyFrame)):
404419
data_source_obj = DataFrameSource(
405-
nw.from_native(data_source).to_pandas(),
420+
nw.to_native(data_source),
406421
table_name,
407422
)
423+
else:
424+
raise TypeError(
425+
"`data_source` must be a Narwhals DataFrame or LazyFrame, or a SQLAlchemy Engine",
426+
)
408427
# Process greeting
409428
if greeting is None:
410429
print(

pyproject.toml

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,20 @@ build-backend = "hatchling.build"
44

55
[project]
66
name = "querychat"
7-
version = "0.1.0"
7+
version = "0.2.0"
88
description = "Chat with your data using natural language"
99
readme = "pkg-py/README.md"
1010
requires-python = ">=3.9"
1111
license = { file = "pkg-py/LICENSE" }
12-
authors = [{ name = "Posit", email = "[email protected]" }]
12+
authors = [
13+
{ name = "Joe Cheng", email = "[email protected]" },
14+
{ name = "Garrick Aden-Buie", email = "[email protected]" },
15+
{ name = "Dan Chen", email = "[email protected]" },
16+
{ name = "Barret Schloerke", email = "[email protected]" }
17+
]
18+
maintainers = [
19+
{ name = "Garrick Aden-Buie", email = "[email protected]" }
20+
]
1321
dependencies = [
1422
"duckdb",
1523
"pandas",

0 commit comments

Comments
 (0)