(orig_values, namask=None)
return valuemap, values, coltype
Use heuristics to guess data type.
Use heuristics to guess data type.
Use heuristics to guess data type .
def guess_data_type(orig_values, namask=None):
    """
    Use heuristics to guess data type.
    """
    valuemap, values = None, orig_values
    is_discrete = is_discrete_values(orig_values)
    orig_values = np.asarray(orig_values, dtype=str)
    if namask is None:
        namask = isnastr(orig_values)
    if is_discrete:
        valuemap = natural_sorted(is_discrete)
        coltype = DiscreteVariable
    else:
        # try to parse as float
        values = np.empty_like(orig_values, dtype=float)
        values[namask] = np.nan
        try:
            np.copyto(values, orig_values, where=~namask, casting="unsafe")
        except ValueError:
            values = orig_values
            coltype = StringVariable
        else:
            coltype = ContinuousVariable

    if coltype is not ContinuousVariable:
        # when not continuous variable it can still be time variable even it
        # was before recognized as a discrete
        tvar = TimeVariable('_')
        # introducing new variable prevent overwriting orig_values and values
        temp_values = np.empty_like(orig_values, dtype=float)
        try:
            temp_values[~namask] = [
                tvar.parse_exact_iso(i) for i in orig_values[~namask]]
        except ValueError:
            pass
        else:
            valuemap = None
            coltype = TimeVariable
            values = temp_values
    return valuemap, values, coltype
def guess_data_type ( orig_values , namask = None ) : valuemap , values = None , orig_values is_discrete = is_discrete_values ( orig_values ) orig_values = np . asarray ( orig_values , dtype = str ) if namask is None : namask = isnastr ( orig_values ) if is_discrete : valuemap = natural_sorted ( is_discrete ) coltype = DiscreteVariable else : # try to parse as float values = np . empty_like ( orig_values , dtype = float ) values [ namask ] = np . nan try : np . copyto ( values , orig_values , where = ~ namask , casting = "unsafe" ) except ValueError : values = orig_values coltype = StringVariable else : coltype = ContinuousVariable if coltype is not ContinuousVariable : # when not continuous variable it can still be time variable even it # was before recognized as a discrete tvar = TimeVariable ( '_' ) # introducing new variable prevent overwriting orig_values and values temp_values = np . empty_like ( orig_values , dtype = float ) try : temp_values [ ~ namask ] = [ tvar . parse_exact_iso ( i ) for i in orig_values [ ~ namask ] ] except ValueError : pass else : valuemap = None coltype = TimeVariable values = temp_values return valuemap , values , coltype