diff --git a/crates/polars-plan/src/utils.rs b/crates/polars-plan/src/utils.rs index 212c8fd92a7d..dfac1f661674 100644 --- a/crates/polars-plan/src/utils.rs +++ b/crates/polars-plan/src/utils.rs @@ -1,5 +1,5 @@ use std::fmt::Formatter; -use std::iter::{FlatMap, Map}; +use std::iter::FlatMap; use std::sync::Arc; use std::vec::IntoIter; @@ -202,10 +202,12 @@ pub(crate) fn get_single_leaf(expr: &Expr) -> PolarsResult> { } #[allow(clippy::type_complexity)] -pub fn expr_to_leaf_column_names_iter(expr: &Expr) -> Map, fn(Expr) -> Arc> { +pub fn expr_to_leaf_column_names_iter( + expr: &Expr, +) -> FlatMap, Option>, fn(Expr) -> Option>> { expr_to_root_column_exprs(expr) .into_iter() - .map(|e| expr_to_leaf_column_name(&e).unwrap()) + .flat_map(|e| expr_to_leaf_column_name(&e).ok()) } /// This should gradually replace expr_to_root_column as this will get all names in the tree. diff --git a/py-polars/polars/expr/expr.py b/py-polars/polars/expr/expr.py index 4d2780db5419..28eccc96f691 100644 --- a/py-polars/polars/expr/expr.py +++ b/py-polars/polars/expr/expr.py @@ -36,7 +36,7 @@ ) from polars.dependencies import _check_for_numpy from polars.dependencies import numpy as np -from polars.exceptions import PolarsInefficientApplyWarning, PolarsPanicError +from polars.exceptions import PolarsInefficientApplyWarning from polars.expr.array import ExprArrayNameSpace from polars.expr.binary import ExprBinaryNameSpace from polars.expr.categorical import ExprCatNameSpace @@ -3806,16 +3806,9 @@ def apply( # input x: Series of type list containing the group values from polars.utils.udfs import warn_on_inefficient_apply - try: - root_names = self.meta.root_names() - except PolarsPanicError: - # no root names for pl.col('*') - pass - else: - if root_names: - warn_on_inefficient_apply( - function, columns=root_names, apply_target="expr" - ) + root_names = self.meta.root_names() + if len(root_names) > 0: + warn_on_inefficient_apply(function, columns=root_names, apply_target="expr") if pass_name: diff --git a/py-polars/tests/unit/operations/test_apply.py b/py-polars/tests/unit/operations/test_apply.py index b8bfe480b738..d7948408cd2f 100644 --- a/py-polars/tests/unit/operations/test_apply.py +++ b/py-polars/tests/unit/operations/test_apply.py @@ -386,3 +386,8 @@ def test_apply_shifted_chunks() -> None: def test_apply_dict_order_10128() -> None: df = pl.select(pl.lit("").apply(lambda x: {"c": 1, "b": 2, "a": 3})) assert df.to_dict(False) == {"literal": [{"c": 1, "b": 2, "a": 3}]} + + +def test_apply_10237() -> None: + df = pl.DataFrame({"a": [1, 2, 3]}) + assert df.select(pl.all().apply(lambda x: x > 50))["a"].to_list() == [False] * 3