diff --git a/crates/polars-lazy/src/physical_plan/exotic.rs b/crates/polars-lazy/src/physical_plan/exotic.rs index 2bbbc73b6948..08673ca1f032 100644 --- a/crates/polars-lazy/src/physical_plan/exotic.rs +++ b/crates/polars-lazy/src/physical_plan/exotic.rs @@ -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 @@ -42,7 +42,7 @@ pub(crate) fn prepare_expression_for_context( &aexpr, ctxt, &expr_arena, - &schema, + &input_schema, &mut ExpressionConversionState::new(true, 0), ) } diff --git a/py-polars/tests/unit/operations/namespaces/list/test_list.py b/py-polars/tests/unit/operations/namespaces/list/test_list.py index dfe6adad08d0..78bda8a3637d 100644 --- a/py-polars/tests/unit/operations/namespaces/list/test_list.py +++ b/py-polars/tests/unit/operations/namespaces/list/test_list.py @@ -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]]}), + )