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)
def test_primitive_measure_str(self): self.assertEqual(str(datashape.int8), 'int8') self.assertEqual(str(datashape.int16), 'int16') self.assertEqual(str(datashape.int32), 'int32') self.assertEqual(str(datashape.int64), 'int64') self.assertEqual(str(datashape.uint8), 'uint8') self.assertEqual(str(datashape.uint16), 'uint16') self.assertEqual(str(datashape.uint32), 'uint32') self.assertEqual(str(datashape.uint64), 'uint64') self.assertEqual(str(datashape.float32), 'float32') self.assertEqual(str(datashape.float64), 'float64') self.assertEqual(str(datashape.string), 'string') self.assertEqual(str(datashape.String(3)), 'string[3]') self.assertEqual(str(datashape.String('A')), "string['A']")
def test_primitive_measure_repr(self): self.assertEqual(repr(datashape.int8), 'ctype("int8")') self.assertEqual(repr(datashape.int16), 'ctype("int16")') self.assertEqual(repr(datashape.int32), 'ctype("int32")') self.assertEqual(repr(datashape.int64), 'ctype("int64")') self.assertEqual(repr(datashape.uint8), 'ctype("uint8")') self.assertEqual(repr(datashape.uint16), 'ctype("uint16")') self.assertEqual(repr(datashape.uint32), 'ctype("uint32")') self.assertEqual(repr(datashape.uint64), 'ctype("uint64")') self.assertEqual(repr(datashape.float32), 'ctype("float32")') self.assertEqual(repr(datashape.float64), 'ctype("float64")') self.assertEqual(repr(datashape.string), 'ctype("string")') self.assertEqual(repr(datashape.String(3)), 'ctype("string[3]")') self.assertEqual(repr(datashape.String('A')), """ctype("string['A']")""")
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)