Skip to content

Commit

Permalink
fix: Fix ColumnNotFound when using pl.element() inside list.eval (
Browse files Browse the repository at this point in the history
  • Loading branch information
nameexhaustion authored Oct 25, 2024
1 parent f01fb7b commit 591971b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
8 changes: 4 additions & 4 deletions crates/polars-lazy/src/physical_plan/exotic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@ pub(crate) fn prepare_expression_for_context(
// create a dummy lazyframe and run a very simple optimization run so that
// type coercion and simplify expression optimizations run.
let column = Series::full_null(name, 0, dtype);
let mut lf = column
.into_frame()
let df = column.into_frame();
let input_schema = Arc::new(df.schema());
let lf = df
.lazy()
.without_optimizations()
.with_simplify_expr(true)
.select([expr.clone()]);
let schema = lf.collect_schema()?;
let optimized = lf.optimize(&mut lp_arena, &mut expr_arena)?;
let lp = lp_arena.get(optimized);
let aexpr = lp
Expand All @@ -42,7 +42,7 @@ pub(crate) fn prepare_expression_for_context(
&aexpr,
ctxt,
&expr_arena,
&schema,
&input_schema,
&mut ExpressionConversionState::new(true, 0),
)
}
11 changes: 11 additions & 0 deletions py-polars/tests/unit/operations/namespaces/list/test_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -900,3 +900,14 @@ def test_list_concat_struct_19279() -> None:
[{"s": "d", "i": 3}],
]
}


def test_list_eval_element_schema_19345() -> None:
assert_frame_equal(
(
pl.LazyFrame({"a": [[{"a": 1}]]})
.select(pl.col("a").list.eval(pl.element().struct.field("a")))
.collect()
),
pl.DataFrame({"a": [[1]]}),
)

0 comments on commit 591971b

Please sign in to comment.