MCPcopy
hub / github.com/pandas-dev/pandas / validate_bool_kwarg

Function validate_bool_kwarg

pandas/util/_validators.py:228–270  ·  view source on GitHub ↗

Ensure that argument passed in arg_name can be interpreted as boolean. Parameters ---------- value : bool Value to be validated. arg_name : str Name of the argument. To be reflected in the error message. none_allowed : bool, default True Whether to c

(
    value: BoolishNoneT,
    arg_name: str,
    none_allowed: bool = True,
    int_allowed: bool = False,
)

Source from the content-addressed store, hash-verified

226
227
228def validate_bool_kwarg(
229 value: BoolishNoneT,
230 arg_name: str,
231 none_allowed: bool = True,
232 int_allowed: bool = False,
233) -> BoolishNoneT:
234 """
235 Ensure that argument passed in arg_name can be interpreted as boolean.
236
237 Parameters
238 ----------
239 value : bool
240 Value to be validated.
241 arg_name : str
242 Name of the argument. To be reflected in the error message.
243 none_allowed : bool, default True
244 Whether to consider None to be a valid boolean.
245 int_allowed : bool, default False
246 Whether to consider integer value to be a valid boolean.
247
248 Returns
249 -------
250 value
251 The same value as input.
252
253 Raises
254 ------
255 ValueError
256 If the value is not a valid boolean.
257 """
258 good_value = is_bool(value)
259 if none_allowed:
260 good_value = good_value or (value is None)
261
262 if int_allowed:
263 good_value = good_value or isinstance(value, int)
264
265 if not good_value:
266 raise ValueError(
267 f'For argument "{arg_name}" expected type bool, received '
268 f"type {type(value).__name__}."
269 )
270 return value
271
272
273def validate_na_arg(value, name: str):

Callers 15

reset_indexMethod · 0.90
_set_nameMethod · 0.90
drop_duplicatesMethod · 0.90
sort_valuesMethod · 0.90
dropnaMethod · 0.90
anyMethod · 0.90
allMethod · 0.90
queryMethod · 0.90
evalMethod · 0.90
set_indexMethod · 0.90
reset_indexMethod · 0.90
dropnaMethod · 0.90

Calls

no outgoing calls

Tested by 2

test_validate_bool_kwargFunction · 0.72