Skip to content

Commit 92943cc

Browse files
committed
patch hugeint to polars decimal
1 parent 511d5e2 commit 92943cc

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

duckdb/polars_io.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,9 +176,14 @@ def _pl_tree_to_sql(tree: _ExpressionTree) -> str:
176176
if dtype.startswith("{'Decimal'") or dtype == "Decimal":
177177
decimal_value = value["Decimal"]
178178
assert isinstance(decimal_value, list), (
179-
f"A {dtype} should be a two member list but got {type(decimal_value)}"
179+
f"A {dtype} should be a two or three member list but got {type(decimal_value)}"
180180
)
181-
return str(Decimal(decimal_value[0]) / Decimal(10 ** decimal_value[1]))
181+
if len(decimal_value) == 2: # pre-polars 1.34.0
182+
return str(Decimal(decimal_value[0]) / Decimal(10 ** decimal_value[1]))
183+
assert len(decimal_value) == 3, ( # since polars 1.34.0
184+
f"A {dtype} should be a two or three member list but got {len(decimal_value)} member list"
185+
)
186+
return str(Decimal(decimal_value[0]) / Decimal(10 ** decimal_value[2]))
182187

183188
# Datetime with microseconds since epoch
184189
if dtype.startswith("{'Datetime'") or dtype == "Datetime":

tests/fast/arrow/test_polars.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ def test_polars_column_with_tricky_name(self, duckdb_cursor):
175175
"UBIGINT",
176176
"FLOAT",
177177
"DOUBLE",
178-
# "HUGEINT",
178+
"HUGEINT",
179179
"DECIMAL(4,1)",
180180
"DECIMAL(9,1)",
181181
"DECIMAL(18,4)",

0 commit comments

Comments
 (0)