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(rust, python): don't allow named expression in arr.eval #5957

Merged
merged 1 commit into from
Dec 30, 2022
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
9 changes: 7 additions & 2 deletions polars/polars-lazy/src/dsl/list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,17 @@ pub trait ListNameSpaceExtension: IntoListNameSpace + Sized {
fn eval(self, expr: Expr, parallel: bool) -> Expr {
let this = self.into_list_name_space();

use crate::physical_plan::exotic::{prepare_eval_expr, prepare_expression_for_context};
use crate::physical_plan::exotic::prepare_expression_for_context;
use crate::physical_plan::state::ExecutionState;
let expr = prepare_eval_expr(expr);

let expr2 = expr.clone();
let func = move |s: Series| {
for name in expr_to_leaf_column_names(&expr) {
if !name.is_empty() {
return Err(PolarsError::ComputeError(r#"Named columns not allowed in 'arr.eval'. Consider using 'element' or 'col("")'."#.into()));
}
}

let lst = s.list()?;
if lst.is_empty() {
// ensure we get the new schema
Expand Down
9 changes: 9 additions & 0 deletions py-polars/tests/unit/test_errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -325,3 +325,12 @@ def test_invalid_dtype() -> None:
match=r"Given dtype: 'mayonnaise' is not a valid Polars data type and cannot be converted into one", # noqa: E501
):
pl.Series([1, 2], dtype="mayonnaise")


def test_arr_eval_named_cols() -> None:
df = pl.DataFrame({"A": ["a", "b"], "B": [["a", "b"], ["c", "d"]]})

with pytest.raises(
pl.ComputeError,
):
df.select(pl.col("B").arr.eval(pl.element().append(pl.col("A"))))