Пример #1
0
def discover_typeengine(typ):
    if isinstance(typ, sa.Interval):
        if typ.second_precision is None and typ.day_precision is None:
            return datashape.TimeDelta(unit='us')
        elif typ.second_precision == 0 and typ.day_precision == 0:
            return datashape.TimeDelta(unit='s')

        if typ.second_precision in units_of_power and not typ.day_precision:
            units = units_of_power[typ.second_precision]
        elif typ.day_precision > 0:
            units = 'D'
        else:
            raise ValueError('Cannot infer INTERVAL type with parameters'
                             'second_precision=%d, day_precision=%d' %
                             (typ.second_precision, typ.day_precision))
        return datashape.TimeDelta(unit=units)
    if typ in revtypes:
        return dshape(revtypes[typ])[0]
    if type(typ) in revtypes:
        return revtypes[type(typ)]
    if isinstance(typ, (sa.NUMERIC, sa.DECIMAL)):
        return datashape.Decimal(precision=typ.precision, scale=typ.scale)
    if isinstance(typ, (sa.String, sa.Unicode)):
        return datashape.String(typ.length, 'U8')
    else:
        for k, v in revtypes.items():
            if isinstance(k, type) and (isinstance(typ, k) or hasattr(
                    typ, 'impl') and isinstance(typ.impl, k)):
                return v
            if k == typ:
                return v
    raise NotImplementedError("No SQL-datashape match for type %s" % typ)
Пример #2
0
def test_timedelta_sql_discovery_hour_minute(freq):
    # these always compare equal to a seconds timedelta, because no data loss
    # will occur with this heuristic. this implies that the sa.Table was
    # constructed with day_precision == 0 and second_precision == 0
    ds = '{name: string, amount: int, duration: timedelta[unit="%s"]}' % freq
    t = dshape_to_table('td_bank', ds)
    assert discover(t).measure['duration'] == datashape.TimeDelta('s')
Пример #3
0
def test_get_numba_type():
    assert get_numba_type(datashape.bool_) == nb.bool_
    assert get_numba_type(datashape.date_) == datetime64('D')
    assert get_numba_type(datashape.datetime_) == datetime64('us')
    assert get_numba_type(datashape.timedelta_) == timedelta64('us')
    assert get_numba_type(datashape.TimeDelta('D')) == timedelta64('D')
    assert get_numba_type(datashape.int64) == int64
    assert get_numba_type(datashape.String(7, "A")) == char(7)
    assert get_numba_type(datashape.String(None, "A")) == nb.types.string
    assert get_numba_type(datashape.String(7)) == unichar(7)
Пример #4
0
def test_timedelta_sql_discovery(freq):
    ds = '{name: string, amount: int, duration: timedelta[unit="%s"]}' % freq
    t = dshape_to_table('td_bank', ds)
    assert discover(t).measure['duration'] == datashape.TimeDelta(freq)