From 2e5e4ecb3be43081bf80ba8b9524f40c37f819bf Mon Sep 17 00:00:00 2001 From: aabhinavg Date: Sun, 14 Apr 2024 09:25:36 +0530 Subject: [PATCH] Modified the function to handle invalid boolean casting by returning None instead of raising a ValueError. This improves robustness and avoids unexpected interruptions in the flow of the program --- pandas/core/arrays/boolean.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pandas/core/arrays/boolean.py b/pandas/core/arrays/boolean.py index 813b10eef5e4b..7e406ca5e039e 100644 --- a/pandas/core/arrays/boolean.py +++ b/pandas/core/arrays/boolean.py @@ -343,7 +343,8 @@ def map_string(s) -> bool: elif s in false_values_union: return False else: - raise ValueError(f"{s} cannot be cast to bool") + print(f"{s} cannot be cast to bool") + return None scalars = np.array(strings, dtype=object) mask = isna(scalars)