def test_namedtuple_types_exception(self): with self.assertRaises(errors.TypingError) as raises: types.NamedTuple(types.uint32, 'p') self.assertIn( "Argument 'types' is not iterable", str(raises.exception) )
def __init__(self, col_names, arr_typs): self.array_types = arr_typs self.col_names = col_names name_args = ["{}={}".format(col_names[i], arr_typs[i]) for i in range(len(col_names))] name = "itertuples({})".format(",".join(name_args)) py_ntup = namedtuple('Pandas', col_names) yield_type = types.NamedTuple([_get_series_dtype(a) for a in arr_typs], py_ntup) super(DataFrameTupleIterator, self).__init__(name, yield_type)
def _gettyperecord_impl(typingctx, codepoint): """ Provides the binding to numba_gettyperecord, returns a `typerecord` namedtuple of properties from the codepoint. """ if not isinstance(codepoint, types.Integer): raise TypingError("codepoint must be an integer") def details(context, builder, signature, args): ll_void = context.get_value_type(types.void) ll_Py_UCS4 = context.get_value_type(_Py_UCS4) ll_intc = context.get_value_type(types.intc) ll_intc_ptr = ll_intc.as_pointer() ll_uchar = context.get_value_type(types.uchar) ll_uchar_ptr = ll_uchar.as_pointer() ll_ushort = context.get_value_type(types.ushort) ll_ushort_ptr = ll_ushort.as_pointer() fnty = lc.Type.function( ll_void, [ ll_Py_UCS4, # code ll_intc_ptr, # upper ll_intc_ptr, # lower ll_intc_ptr, # title ll_uchar_ptr, # decimal ll_uchar_ptr, # digit ll_ushort_ptr, # flags ]) fn = builder.module.get_or_insert_function(fnty, name="numba_gettyperecord") upper = cgutils.alloca_once(builder, ll_intc, name='upper') lower = cgutils.alloca_once(builder, ll_intc, name='lower') title = cgutils.alloca_once(builder, ll_intc, name='title') decimal = cgutils.alloca_once(builder, ll_uchar, name='decimal') digit = cgutils.alloca_once(builder, ll_uchar, name='digit') flags = cgutils.alloca_once(builder, ll_ushort, name='flags') byref = [upper, lower, title, decimal, digit, flags] builder.call(fn, [args[0]] + byref) buf = [] for x in byref: buf.append(builder.load(x)) res = context.make_tuple(builder, signature.return_type, tuple(buf)) return impl_ret_untracked(context, builder, signature.return_type, res) tupty = types.NamedTuple([ types.intc, types.intc, types.intc, types.uchar, types.uchar, types.ushort ], typerecord) sig = tupty(_Py_UCS4) return sig, details
def test_namedtuple(self): v = Point(1, 2) tp_point = typeof(v) self.assertEqual(tp_point, types.NamedUniTuple(types.intp, 2, Point)) v = Point(1, 2.0) self.assertEqual(typeof(v), types.NamedTuple([types.intp, types.float64], Point)) w = Rect(3, 4) tp_rect = typeof(w) self.assertEqual(tp_rect, types.NamedUniTuple(types.intp, 2, Rect)) self.assertNotEqual(tp_rect, tp_point) self.assertNotEqual(tp_rect, types.UniTuple(tp_rect.dtype, tp_rect.count))
def test_namedtuples(self): ty1 = types.NamedUniTuple(types.intp, 2, Point) self.check_pickling(ty1) ty2 = types.NamedTuple((types.intp, types.float64), Point) self.check_pickling(ty2)