in sourcecode/scoring/pandas_utils.py [0:0]
def _get_check(self, lines: List[str], kwargs: Dict) -> Callable:
"""Return a function which will either assert a condition or append to a list of errors.
Note that this function does not actually log to stderr, but rather appends to a list so
that all
"""
unsafeAllowed = set()
if "unsafeAllowed" in kwargs:
unsafeAllowedArg = kwargs["unsafeAllowed"]
if isinstance(unsafeAllowedArg, str):
unsafeAllowed = {unsafeAllowedArg}
elif isinstance(unsafeAllowedArg, List):
unsafeAllowed = set(unsafeAllowedArg)
else:
assert isinstance(unsafeAllowedArg, Set)
unsafeAllowed = unsafeAllowedArg
del kwargs["unsafeAllowed"]
def _check(columns: Any, condition: bool, msg: str):
if isinstance(columns, str):
failDisabled = columns in unsafeAllowed
elif isinstance(columns, List):
failDisabled = all(col in unsafeAllowed for col in columns)
else:
# Note there are multiple circumstances where the type of Columns may not be a str
# or List[str], including when we are concatenating a Series (column name will be
# set to None), when there are mulit-level column names (column name will be a tuple)
# or when Pandas has set column names to a RangeIndex.
failDisabled = False
if self._fail and not failDisabled:
assert condition, msg
elif not condition:
if failDisabled:
lines.append(f"{msg} (allowed)")
else:
lines.append(f"{msg} (UNALLOWED)")
return _check