Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Fix ColumnNotFound when using pl.element() inside list.eval #19438

Merged
merged 1 commit into from
Oct 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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()?;
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We accidentally passed the output schema instead of the input schema to create_physical_expr

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]]}),
)