-
Notifications
You must be signed in to change notification settings - Fork 32
Open
Labels
Description
What happens?
When registering a Python UDF that returns a union of float/varchar/int, calling the function in duckdb will raise a Conversion Error if the result contains a float value.
See duckdb/duckdb#19309 for full discussion.
To Reproduce
Snippet to reproduce the issue:
import duckdb
import numpy as np
from duckdb.typing import (
DuckDBPyType
)
arr = [{"a": 1, "b": 1.2}, {"a": 3, "b": 2.4}]
def test():
return arr
return_type = DuckDBPyType(list[dict[str, Union[str, int, np.float64, np.float32, float]]])
duckdb.create_function("test", test, return_type=return_type)
duckdb.sql("select test()")
ConversionException: Conversion Error: Could not convert 'float' to type UNION(u1 VARCHAR, u2 BIGINT, u3 DOUBLE, u4 FLOAT, u5 DOUBLE)
As stated in previous section, there's no issue if the result doesn't contains any float value:
arr = [{"a": 1, "b": "abc"}, {"a": 3, "b": "def"}]
duckdb.sql("select test()")
┌──────────────────────────────────────────────────────────────────────────────┐
│ test() │
│ map(varchar, union(u1 varchar, u2 bigint, u3 double, u4 float, u5 double))[] │
├──────────────────────────────────────────────────────────────────────────────┤
│ [{a=1, b=abc}, {a=3, b=def}] │
└──────────────────────────────────────────────────────────────────────────────┘
OS:
Windows 11
DuckDB Package Version:
1.4.0
Python Version:
3.12.9
Full Name:
Maxime Nguyen
Affiliation:
Credit Mutuel AM
What is the latest build you tested with? If possible, we recommend testing with the latest nightly build.
I have tested with a stable release
Did you include all relevant data sets for reproducing the issue?
Yes
Did you include all code required to reproduce the issue?
- Yes, I have
Did you include all relevant configuration to reproduce the issue?
- Yes, I have