Skip to content

Commit

Permalink
feat(python): raise more informative error message if someone lands o…
Browse files Browse the repository at this point in the history
…n Expr.__bool__ (#14067)
  • Loading branch information
MarcoGorelli committed Jan 29, 2024
1 parent ee97eb8 commit 3cf4b69
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions py-polars/polars/expr/expr.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,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)

Expand Down

0 comments on commit 3cf4b69

Please sign in to comment.