Skip to content

functions decorated with daft.func don't respect the input type signature #5462

@universalmind303

Description

@universalmind303

Describe the bug

if you have invalid types for native expressions such as using upper on a list[int], you get a type error during planning stating that the input is not of the correct type.

df = daft.from_pydict({"ints_list": [[1], [1, 2, 3]]})
df = df.select(daft.functions.upper(df["ints_list"]))
df.show()
daft.exceptions.DaftCoreException: DaftError::External Unable to create logical plan node.
Due to: DaftError::TypeError Expects input to 'upper' to be utf8, but received List[Int64]

but if you use a udf, the type signature is ignored, and results in a runtime error.

@daft.func
def my_upper(s: str) -> str: # s is actually a list[int] and the type signature is ignored
    return s.upper()

df = df.select(my_upper(df["ints_list"]))
df.show()
daft.exceptions.DaftCoreException: DaftError::ComputeError Error processing some rows:
0: DaftError::PyO3Error AttributeError: 'list' object has no attribute 'upper'

To Reproduce

see above

Expected behavior

if i have a function like:

@daft.func
def my_upper(s: str) -> str: ...

I'd expect daft to recognize that I expect this to only accept strings and error during planning time instead of failing during execution.

I'd want to get the same error message as you get with the native expressions

Due to: DaftError::TypeError Expects input to 'my_upper' to be utf8, but received List[Int64]

Component(s)

Expressions

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requesthelp wantedExtra attention is neededtypesIssues related to the type system

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions