Skip to content

Commit

Permalink
fix(python): Raise if invalid strategy is passed to map_elements (#…
Browse files Browse the repository at this point in the history
…14397)

Co-authored-by: Stijn de Gooijer <[email protected]>
  • Loading branch information
MarcoGorelli and stinodego authored Feb 9, 2024
1 parent 5006426 commit de02091
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
3 changes: 2 additions & 1 deletion py-polars/polars/expr/expr.py
Original file line number Diff line number Diff line change
Expand Up @@ -4411,7 +4411,8 @@ def get_lazy_promise(df: DataFrame) -> LazyFrame:
wrap_threading, agg_list=True, return_dtype=return_dtype
)
else:
ValueError(f"Strategy {strategy} is not supported.")
msg = f"strategy {strategy!r} is not supported"
raise ValueError(msg)

def flatten(self) -> Self:
"""
Expand Down
8 changes: 8 additions & 0 deletions py-polars/tests/unit/operations/map/test_map_elements.py
Original file line number Diff line number Diff line change
Expand Up @@ -300,3 +300,11 @@ def test_apply_deprecated() -> None:
pl.col("a").apply(np.abs)
with pytest.deprecated_call():
pl.Series([1, 2, 3]).apply(np.abs)


def test_cabbage_strategy_14396() -> None:
df = pl.DataFrame({"x": [1, 2, 3]})
with pytest.raises(
ValueError, match="strategy 'cabbage' is not supported"
), pytest.warns(PolarsInefficientMapWarning):
df.select(pl.col("x").map_elements(lambda x: 2 * x, strategy="cabbage")) # type: ignore[arg-type]

0 comments on commit de02091

Please sign in to comment.