Skip to content

Commit

Permalink
feat(python): make Series.__bool__ error message Rusttier (#15407)
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcoGorelli authored Mar 31, 2024
1 parent cd1994b commit 1485fec
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions py-polars/polars/series/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -607,8 +607,12 @@ def shape(self) -> tuple[int]:
def __bool__(self) -> NoReturn:
msg = (
"the truth value of a Series is ambiguous"
"\n\nHint: use '&' or '|' to chain Series boolean results together, not and/or."
" To check if a Series contains any values, use `is_empty()`."
"\n\n"
"Here are some things you might want to try:\n"
"- instead of `if s`, use `if not s.is_empty()`\n"
"- instead of `s1 and s2`, use `s1 & s2`\n"
"- instead of `s1 or s2`, use `s1 | s2`\n"
"- instead of `s in [y, z]`, use `s.is_in([y, z])`\n"
)
raise TypeError(msg)

Expand Down

0 comments on commit 1485fec

Please sign in to comment.