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: Properly catch not found explode cols #17020

Merged
merged 1 commit into from
Jun 17, 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
10 changes: 6 additions & 4 deletions crates/polars-plan/src/logical_plan/functions/dsl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,13 @@ impl DslFunction {
let columns = columns
.iter()
.map(|e| {
if let Expr::Column(name) = e {
Ok(name.clone())
} else {
let Expr::Column(name) = e else {
polars_bail!(InvalidOperation: "expected column expression")
}
};

polars_ensure!(input_schema.contains(name), ColumnNotFound: "{name}");

Ok(name.clone())
})
.collect::<PolarsResult<Arc<[Arc<str>]>>>()?;
FunctionNode::Explode {
Expand Down
7 changes: 7 additions & 0 deletions py-polars/tests/unit/operations/test_explode.py
Original file line number Diff line number Diff line change
Expand Up @@ -430,3 +430,10 @@ def test_expr_str_explode_deprecated() -> None:

expected = pl.Series("a", ["H", "e", "l", "l", "o", "W", "o", "r", "l", "d"])
assert_series_equal(result, expected)


def test_undefined_col_15852() -> None:
lf = pl.LazyFrame({"foo": [1]})

with pytest.raises(pl.exceptions.ColumnNotFoundError):
lf.explode("bar").join(lf, on="foo").collect()