@@ -257,6 +257,8 @@ class BooleanArray(BaseMaskedArray):
257
257
258
258
# The value used to fill '_data' to avoid upcasting
259
259
_internal_fill_value = False
260
+ _TRUE_VALUES = {"True" , "TRUE" , "true" , "1" , "1.0" }
261
+ _FALSE_VALUES = {"False" , "FALSE" , "false" , "0" , "0.0" }
260
262
261
263
def __init__ (self , values : np .ndarray , mask : np .ndarray , copy : bool = False ):
262
264
if not (isinstance (values , np .ndarray ) and values .dtype == np .bool_ ):
@@ -282,14 +284,23 @@ def _from_sequence(
282
284
283
285
@classmethod
284
286
def _from_sequence_of_strings (
285
- cls , strings : List [str ], * , dtype : Optional [Dtype ] = None , copy : bool = False
287
+ cls ,
288
+ strings : List [str ],
289
+ * ,
290
+ dtype : Optional [Dtype ] = None ,
291
+ copy : bool = False ,
292
+ true_values : Optional [List [str ]] = None ,
293
+ false_values : Optional [List [str ]] = None ,
286
294
) -> "BooleanArray" :
295
+ true_values_union = cls ._TRUE_VALUES .union (true_values or [])
296
+ false_values_union = cls ._FALSE_VALUES .union (false_values or [])
297
+
287
298
def map_string (s ):
288
299
if isna (s ):
289
300
return s
290
- elif s in [ "True" , "TRUE" , "true" , "1" , "1.0" ] :
301
+ elif s in true_values_union :
291
302
return True
292
- elif s in [ "False" , "FALSE" , "false" , "0" , "0.0" ] :
303
+ elif s in false_values_union :
293
304
return False
294
305
else :
295
306
raise ValueError (f"{ s } cannot be cast to bool" )
0 commit comments