Skip to content

Commit 85a76eb

Browse files
committed
fix(duckdb): use fetch_arrow_table() to be able to handle big timestamps
1 parent b22532c commit 85a76eb

File tree

8 files changed

+201
-172
lines changed

8 files changed

+201
-172
lines changed

ibis/backends/duckdb/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,8 @@ def fetch_from_cursor(
153153
cursor: duckdb.DuckDBPyConnection,
154154
schema: sch.Schema,
155155
):
156-
df = cursor.cursor.fetch_df()
156+
table = cursor.cursor.fetch_arrow_table()
157+
df = table.to_pandas(timestamp_as_object=True)
157158
return schema.apply_to(df)
158159

159160
def _metadata(self, query: str) -> Iterator[_ColumnMetadata]:

ibis/backends/pandas/client.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,11 @@ def convert_element(values, names=out_dtype.names):
289289
return column.map(convert_element)
290290

291291

292+
@sch.convert.register(np.dtype, dt.Array, pd.Series)
293+
def convert_array_to_series(in_dtype, out_dtype, column):
294+
return column.map(lambda x: x if x is None else list(x))
295+
296+
292297
dt.DataType.to_pandas = ibis_dtype_to_pandas # type: ignore
293298
sch.Schema.to_pandas = ibis_schema_to_pandas # type: ignore
294299

ibis/backends/tests/test_temporal.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -857,8 +857,8 @@ def test_integer_cast_to_timestamp(backend, alltypes, df):
857857
),
858858
)
859859
@pytest.mark.notimpl(
860-
["datafusion", "duckdb"],
861-
reason="DataFusion and DuckDB backends assume ns resolution timestamps",
860+
["datafusion"],
861+
reason="DataFusion backend assumes ns resolution timestamps",
862862
)
863863
@pytest.mark.notyet(
864864
["pyspark"],

ibis/expr/schema.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -389,7 +389,7 @@ def apply_to(self, df: pd.DataFrame) -> pd.DataFrame:
389389
# assume not equal
390390
not_equal = True
391391

392-
if not_equal or isinstance(dtype, (dt.String, dt.Struct)):
392+
if not_equal or not isinstance(dtype, dt.Primitive):
393393
new_col = convert(col_dtype, dtype, col)
394394
else:
395395
new_col = col

0 commit comments

Comments
 (0)