Skip to content

Commit

Permalink
fix(rust, python): keep dtype when eval on empty list (#5597)
Browse files Browse the repository at this point in the history
  • Loading branch information
ritchie46 committed Nov 23, 2022
1 parent 082374e commit 63907fc
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
3 changes: 3 additions & 0 deletions polars/polars-lazy/src/dsl/list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ pub trait ListNameSpaceExtension: IntoListNameSpace + Sized {
let expr2 = expr.clone();
let func = move |s: Series| {
let lst = s.list()?;
if lst.is_empty() {
return Ok(s);
}

let phys_expr =
prepare_expression_for_context("", &expr, &lst.inner_dtype(), Context::Default)?;
Expand Down
14 changes: 14 additions & 0 deletions py-polars/tests/unit/test_lists.py
Original file line number Diff line number Diff line change
Expand Up @@ -545,3 +545,17 @@ def test_list_sliced_get_5186() -> None:
]
)
)


def test_empty_eval_dtype_5546() -> None:
df = pl.DataFrame([{"a": [{"name": 1}, {"name": 2}]}])

dtype = df.dtypes[0]

assert (
df.limit(0).with_column(
pl.col("a")
.arr.eval(pl.element().filter(pl.first().struct.field("name") == 1))
.alias("a_filtered")
)
).dtypes == [dtype, dtype]

0 comments on commit 63907fc

Please sign in to comment.