Skip to content

Commit

Permalink
fix: properly catch not found explode cols (#17020)
Browse files Browse the repository at this point in the history
  • Loading branch information
coastalwhite authored Jun 17, 2024
1 parent 4a34528 commit 69e3824
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
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()

0 comments on commit 69e3824

Please sign in to comment.