From 1902f3593bb8cf3c4ab1be82e89a22f6d87d3c4f Mon Sep 17 00:00:00 2001 From: MarcoGorelli <33491632+MarcoGorelli@users.noreply.github.com> Date: Mon, 29 Jan 2024 10:30:21 +0000 Subject: [PATCH] feat(python): raise more informative error message if someone lands on Expr.__bool__ --- py-polars/polars/expr/expr.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/py-polars/polars/expr/expr.py b/py-polars/polars/expr/expr.py index de83d8da4da7..43468daa2f5b 100644 --- a/py-polars/polars/expr/expr.py +++ b/py-polars/polars/expr/expr.py @@ -143,8 +143,13 @@ def __str__(self) -> str: def __bool__(self) -> NoReturn: msg = ( "the truth value of an Expr is ambiguous" - "\n\nHint: use '&' or '|' to logically combine Expr, not 'and'/'or', and" - " use `x.is_in([y,z])` instead of `x in [y,z]` to check membership." + "\n\n" + "You probably got here by using a Python standard library function instead " + "of the native expressions API.\n" + "Here are some things you might want to try:\n" + "- instead of `pl.col('a') and pl.col('b')`, use `pl.col('a') & pl.col('b')`\n" + "- instead of `pl.col('a') in [y, z]`, use `pl.col('a').is_in([y, z])`\n" + "- instead of `max(pl.col('a'), pl.col('b'))`, use `pl.max_horizontal(pl.col('a'), pl.col('b'))`\n" ) raise TypeError(msg)