From 1485fec63a2550d06253cc18dc1d5e5e2f68bf94 Mon Sep 17 00:00:00 2001 From: Marco Edward Gorelli Date: Sun, 31 Mar 2024 11:18:52 +0100 Subject: [PATCH] feat(python): make Series.__bool__ error message Rusttier (#15407) --- py-polars/polars/series/series.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/py-polars/polars/series/series.py b/py-polars/polars/series/series.py index 3bd8026651db..a651f8f77508 100644 --- a/py-polars/polars/series/series.py +++ b/py-polars/polars/series/series.py @@ -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)