77import duckdb
88import narwhals .stable .v1 as nw
99import pytest
10- from querychat ._df_compat import duckdb_result_to_nw , read_csv
10+ from querychat ._df_compat import duckdb_result_to_polars , read_csv
1111
1212# Check if polars and pyarrow are available (both needed for DuckDB + polars)
1313try :
@@ -60,8 +60,11 @@ def test_read_csv_data_integrity(self, gzip_csv_file):
6060 assert names == ["Alice" , "Bob" , "Charlie" ]
6161
6262
63- class TestDuckdbResultToNw :
64- """Tests for the duckdb_result_to_nw function."""
63+ @pytest .mark .skipif (
64+ not HAS_POLARS_WITH_PYARROW , reason = "polars or pyarrow not installed"
65+ )
66+ class TestDuckdbResultToPolars :
67+ """Tests for the duckdb_result_to_polars function."""
6568
6669 @pytest .fixture
6770 def duckdb_conn (self ):
@@ -73,16 +76,16 @@ def duckdb_conn(self):
7376 yield conn
7477 conn .close ()
7578
76- def test_duckdb_result_returns_narwhals_dataframe (self , duckdb_conn ):
77- """Test that duckdb_result_to_nw returns a narwhals DataFrame."""
79+ def test_duckdb_result_returns_polars_dataframe (self , duckdb_conn ):
80+ """Test that duckdb_result_to_polars returns a polars DataFrame."""
7881 result = duckdb_conn .execute ("SELECT * FROM test" )
79- df = duckdb_result_to_nw (result )
80- assert isinstance (df , nw .DataFrame )
82+ df = duckdb_result_to_polars (result )
83+ assert isinstance (df , pl .DataFrame )
8184
8285 def test_duckdb_result_has_correct_data (self , duckdb_conn ):
83- """Test that duckdb_result_to_nw preserves data correctly."""
86+ """Test that duckdb_result_to_polars preserves data correctly."""
8487 result = duckdb_conn .execute ("SELECT * FROM test ORDER BY id" )
85- df = duckdb_result_to_nw (result )
88+ df = duckdb_result_to_polars (result )
8689
8790 assert df .shape == (2 , 3 )
8891 assert list (df .columns ) == ["id" , "name" , "value" ]
@@ -92,9 +95,9 @@ def test_duckdb_result_has_correct_data(self, duckdb_conn):
9295 def test_duckdb_result_empty_query (self , duckdb_conn ):
9396 """Test handling of empty query results."""
9497 result = duckdb_conn .execute ("SELECT * FROM test WHERE id > 100" )
95- df = duckdb_result_to_nw (result )
98+ df = duckdb_result_to_polars (result )
9699
97- assert isinstance (df , nw .DataFrame )
100+ assert isinstance (df , pl .DataFrame )
98101 assert df .shape == (0 , 3 )
99102
100103
@@ -117,18 +120,3 @@ def test_read_csv_uses_polars_when_available(self):
117120 assert isinstance (native , pl .DataFrame )
118121 finally :
119122 Path (temp_path ).unlink ()
120-
121- def test_duckdb_result_uses_polars_when_available (self ):
122- """Test that duckdb_result_to_nw uses polars when available."""
123- conn = duckdb .connect (":memory:" )
124- conn .execute ("CREATE TABLE t (x INTEGER)" )
125- conn .execute ("INSERT INTO t VALUES (1)" )
126-
127- result = conn .execute ("SELECT * FROM t" )
128- df = duckdb_result_to_nw (result )
129-
130- # The native frame should be polars when polars is available
131- native = df .to_native ()
132- assert isinstance (native , pl .DataFrame )
133-
134- conn .close ()
0 commit comments