def unbox_dataframe(typ, val, c): """unbox dataframe to an empty DataFrame struct columns will be extracted later if necessary. """ n_cols = len(typ.columns) column_strs = [ numba.unicode.make_string_from_constant(c.context, c.builder, string_type, a) for a in typ.columns ] # create dataframe struct and store values dataframe = cgutils.create_struct_proxy(typ)(c.context, c.builder) column_tup = c.context.make_tuple(c.builder, types.UniTuple(string_type, n_cols), column_strs) zero = c.context.get_constant(types.int8, 0) unboxed_tup = c.context.make_tuple( c.builder, types.UniTuple(types.int8, n_cols + 1), [zero] * (n_cols + 1)) # TODO: support unboxing index if typ.index == types.none: dataframe.index = c.context.get_constant(types.none, None) dataframe.columns = column_tup dataframe.unboxed = unboxed_tup dataframe.parent = val # increase refcount of stored values if c.context.enable_nrt: # TODO: other objects? for var in column_strs: c.context.nrt.incref(c.builder, string_type, var) return NativeValue(dataframe._getvalue())
def unbox_dataframe(typ, val, c): """unbox dataframe to an empty DataFrame struct columns will be extracted later if necessary. """ n_cols = len(typ.columns) column_strs = [ numba.unicode.make_string_from_constant(c.context, c.builder, string_type, a) for a in typ.columns ] # create dataframe struct and store values dataframe = cgutils.create_struct_proxy(typ)(c.context, c.builder) column_tup = c.context.make_tuple(c.builder, types.UniTuple(string_type, n_cols), column_strs) # this unboxes all DF columns so that no column unboxing occurs later for col_ind in range(n_cols): series_obj = c.pyapi.object_getattr_string(val, typ.columns[col_ind]) arr_obj = c.pyapi.object_getattr_string(series_obj, "values") ty_series = typ.data[col_ind] if isinstance(ty_series, types.Array): native_val = unbox_array(typ.data[col_ind], arr_obj, c) elif ty_series == string_array_type: native_val = unbox_str_series(string_array_type, series_obj, c) dataframe.data = c.builder.insert_value(dataframe.data, native_val.value, col_ind) # TODO: support unboxing index if typ.index == types.none: dataframe.index = c.context.get_constant(types.none, None) if typ.index == string_array_type: index_obj = c.pyapi.object_getattr_string(val, "index") dataframe.index = unbox_str_series(string_array_type, index_obj, c).value if isinstance(typ.index, types.Array): index_obj = c.pyapi.object_getattr_string(val, "index") index_data = c.pyapi.object_getattr_string(index_obj, "_data") dataframe.index = unbox_array(typ.index, index_data, c).value dataframe.columns = column_tup dataframe.parent = val # increase refcount of stored values if c.context.enable_nrt: # TODO: other objects? for var in column_strs: c.context.nrt.incref(c.builder, string_type, var) return NativeValue(dataframe._getvalue())