[docs]defvalidate_triad_var_name(expr:str)->bool:"""Check if ``expr`` is a valid Triad variable name based on Triad standard: it has to be a valid python identifier and it can't be purely ``_`` .. note:: Any valid triad var name can be used as column names without quote ` ` :param expr: column name expression :return: whether it is valid """ifnotisinstance(expr,str)ornotexpr.isidentifier()ornotexpr.isascii():returnFalsereturnexpr.strip("_")!=""
[docs]defassert_triad_var_name(expr:str)->str:"""Check if ``expr`` is a valid Triad variable name based on Triad standard: it has to be a valid python identifier and it can't be purely ``_`` :param expr: column name expression :raises AssertionError: if the expression is invalid :return: the expression string """ifvalidate_triad_var_name(expr):returnexprraiseAssertionError(f"{expr} is not a valid Triad variable name")