Currently, when you pass a series into daft.lit, i...
# daft-dev
k
Currently, when you pass a series into daft.lit, it actually uses that series as essentially a column instead of a singular list value, which I find to be kind of strange compared to other literal types. Is this intended behavior? For example, when I run
Copy code
>>> import daft
>>> df = daft.from_pydict({"foo": [1, 2, 3], "bar": ["a", "b", "c"]})
>>> s = daft.Series.from_pylist(["x", "y", "z"])
>>> df = df.with_column("baz", daft.lit(s))
>>> df.show()
I get
Copy code
╭───────┬──────┬──────╮
│ foo   ┆ bar  ┆ baz  │
│ ---   ┆ ---  ┆ ---  │
│ Int64 ┆ Utf8 ┆ Utf8 │
╞═══════╪══════╪══════╡
│ 1     ┆ a    ┆ x    │
├╌╌╌╌╌╌╌┼╌╌╌╌╌╌┼╌╌╌╌╌╌┤
│ 2     ┆ b    ┆ y    │
├╌╌╌╌╌╌╌┼╌╌╌╌╌╌┼╌╌╌╌╌╌┤
│ 3     ┆ c    ┆ z    │
╰───────┴──────┴──────╯
when instead I would expect
Copy code
╭───────┬──────┬─────────────────╮
│ foo   ┆ bar  ┆ baz             │
│ ---   ┆ ---  ┆ ---             │
│ Int64 ┆ Utf8 ┆ List[Utf8]      │
╞═══════╪══════╪═════════════════╡
│ 1     ┆ a    ┆ ['x', 'y', 'z'] │
├╌╌╌╌╌╌╌┼╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┤
│ 2     ┆ b    ┆ ['x', 'y', 'z'] │
├╌╌╌╌╌╌╌┼╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┤
│ 3     ┆ c    ┆ ['x', 'y', 'z'] │
╰───────┴──────┴─────────────────╯
c
i think i came across this a few months ago as well and found the behavior odd.
c
It's cuz
eval_expression
on a
lit(series)
just returns the series.
Tbh im not sure how to take a lit series and broadcast it
c
Is ur intention to create a list column from a literal list?
k
We could turn it into a listarray with one element and it would be broadcasted properly.
The reason I am asking is because I'm wondering if we can assume that literals are always a single row. Trying to work out some aggregation validation logic
c
'
c
We could turn it into a listarray with one element and it would be broadcasted properly.
Oh sweet! Yeah that’ll work
k
I guess the question I really have is if doing that would be a breaking change or if this is actually just a bug
c
It would be a bug, and would fail for example if u try and append a series lit to a concated dataframe.
k
Sounds good, will make a PR to fix this then
🙌 1
c
Awesome, just a heads up I believe the ‘is_in’ and ‘count_matches’ expressions depend on series lits
k
gotcha, thanks for the heads up
I would actually like to get some other SQL stuff done first so I documented this bug in an issue for now: https://github.com/Eventual-Inc/Daft/issues/3287