(dat, variable, expected_type=None, expected_name="")
return variable
Get the variable instance from data.
Get the variable instance from data.
Get the variable instance from data .
def _get_variable(dat, variable, expected_type=None, expected_name=""):
    """Get the variable instance from data."""
    failed = False
    if isinstance(variable, data.Variable):
        datvar = getattr(dat, "variable", None)
        if datvar is not None and datvar is not variable:
            raise ValueError("variable does not match the variable in the data")
    elif hasattr(dat, "domain"):
        variable = dat.domain[variable]
    elif hasattr(dat, "variable"):
        variable = dat.variable
    else:
        failed = True
    if failed or (expected_type is not None and not isinstance(variable, expected_type)):
        if isinstance(variable, data.Variable):
            raise ValueError("expected %s variable not %s" % (expected_name, variable))
        else:
            raise ValueError("expected %s, not '%s'" % (
                expected_type.__name__, type(variable).__name__))
    return variable
def _get_variable ( dat , variable , expected_type = None , expected_name = "" ) : failed = False if isinstance ( variable , data . Variable ) : datvar = getattr ( dat , "variable" , None ) if datvar is not None and datvar is not variable : raise ValueError ( "variable does not match the variable in the data" ) elif hasattr ( dat , "domain" ) : variable = dat . domain [ variable ] elif hasattr ( dat , "variable" ) : variable = dat . variable else : failed = True if failed or ( expected_type is not None and not isinstance ( variable , expected_type ) ) : if isinstance ( variable , data . Variable ) : raise ValueError ( "expected %s variable not %s" % ( expected_name , variable ) ) else : raise ValueError ( "expected %s, not '%s'" % ( expected_type . __name__ , type ( variable ) . __name__ ) ) return variable