querychat 0.2.0__tar.gz → 0.2.1__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: querychat
3
- Version: 0.2.0
3
+ Version: 0.2.1
4
4
  Summary: Chat with your data using natural language
5
5
  Project-URL: Homepage, https://github.com/posit-dev/querychat
6
6
  Project-URL: Repository, https://github.com/posit-dev/querychat
@@ -18,7 +18,7 @@ from typing import (
18
18
 
19
19
  import chatlas
20
20
  import chevron
21
- import narwhals as nw
21
+ import narwhals.stable.v1 as nw
22
22
  import sqlalchemy
23
23
  from shiny import Inputs, Outputs, Session, module, reactive, ui
24
24
 
@@ -26,7 +26,7 @@ from ._utils import temp_env_vars
26
26
 
27
27
  if TYPE_CHECKING:
28
28
  import pandas as pd
29
- from narwhals.typing import IntoFrame
29
+ from narwhals.stable.v1.typing import IntoFrame
30
30
 
31
31
  from .datasource import DataFrameSource, DataSource, SQLAlchemySource
32
32
 
@@ -224,16 +224,15 @@ def df_to_html(df: IntoFrame, maxrows: int = 5) -> str:
224
224
  HTML string representation of the table
225
225
 
226
226
  """
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)
227
+ ndf = nw.from_native(df)
228
+
229
+ if isinstance(ndf, (nw.LazyFrame, nw.DataFrame)):
230
+ df_short = ndf.lazy().head(maxrows).collect()
231
+ nrow_full = ndf.lazy().select(nw.len()).collect().item()
235
232
  else:
236
- raise TypeError("df must be a Narwhals DataFrame or LazyFrame")
233
+ raise TypeError(
234
+ "Must be able to convert `df` into a Narwhals DataFrame or LazyFrame",
235
+ )
237
236
 
238
237
  # Generate HTML table
239
238
  table_html = df_short.to_pandas().to_html(
@@ -242,9 +241,9 @@ def df_to_html(df: IntoFrame, maxrows: int = 5) -> str:
242
241
  )
243
242
 
244
243
  # Add note about truncated rows if needed
245
- if len(df_short) != len(ndf_eager):
244
+ if len(df_short) != nrow_full:
246
245
  rows_notice = (
247
- f"\n\n(Showing only the first {maxrows} rows out of {len(ndf_eager)}.)\n"
246
+ f"\n\n(Showing only the first {maxrows} rows out of {nrow_full}.)\n"
248
247
  )
249
248
  else:
250
249
  rows_notice = ""
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
4
4
 
5
5
  [project]
6
6
  name = "querychat"
7
- version = "0.2.0"
7
+ version = "0.2.1"
8
8
  description = "Chat with your data using natural language"
9
9
  readme = "pkg-py/README.md"
10
10
  requires-python = ">=3.9"
File without changes
File without changes
File without changes
File without changes