Skip to content

bug: daft.method(unnest=True) returns the original with_column name #5448

@everettVT

Description

@everettVT

Describe the bug

Instead of returning the names of the fields from a struct, the original name is applied to multiple columns yielding an ambiguous column reference error when selecting on "result' or no column name found on "bar'.

To Reproduce

import daft 

@daft.cls()
class Foo:
    def __init__(self, x: str):
         self.x = x

    @daft.method(
        return_dtype=daft.DataType.struct({
            "bar": daft.DataType.string(),
            "some_int": daft.DataType.int64(),
        }),
        unnest=True
    )
    def do_something(self, input: str):
        return {
            "bar": input + self.x,
            "some_int": 3,
        }

foobar = Foo("bar")

df = daft.from_pydict({"input": ["daft is cool"]}).with_column("result", foobar.do_something(daft.col("input")))

df.show()

# Returns 
╭──────────────┬─────────────────┬────────╮
│ inputresultresult │
│ ---------    │
│ StringStringInt64  │
╞══════════════╪═════════════════╪════════╡
│ daft is cooldaft is coolbar3      │
╰──────────────┴─────────────────┴────────╯

Expected behavior

Should return

╭──────────────┬─────────────────┬──────────╮
│ input        ┆ bar             ┆ some_int │
│ ---          ┆ ---             ┆ ---      │
│ String       ┆ String          ┆ Int64    │
╞══════════════╪═════════════════╪══════════╡
│ daft is cool ┆ daft is coolbar ┆ 3        │
╰──────────────┴─────────────────┴──────────╯

Component(s)

Other

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingp2 (backlog)Nice to have features

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions