示例#1
0
def lower_unbox_df_column(context, builder, sig, args):
    # FIXME: last arg should be types.DType?
    pyapi = context.get_python_api(builder)
    c = numba.pythonapi._UnboxContext(context, builder, pyapi)

    # TODO: refcounts?
    col_ind = sig.args[1].value
    col_name = sig.args[0].col_names[col_ind]
    series_obj = c.pyapi.object_getattr_string(args[0], col_name)
    arr_obj = c.pyapi.object_getattr_string(series_obj, "values")

    if isinstance(sig.args[2],
                  types.Const) and sig.args[2].value == 11:  # FIXME: str code
        native_val = unbox_str_series(string_array_type, arr_obj, c)
    else:
        if isinstance(
                sig.args[2],
                types.Const) and sig.args[2].value == 12:  # FIXME: dt64 code
            dtype = types.NPDatetime('ns')
        else:
            dtype = sig.args[2].dtype
        # TODO: error handling like Numba callwrappers.py
        native_val = unbox_array(types.Array(dtype=dtype, ndim=1, layout='C'),
                                 arr_obj, c)

    c.pyapi.decref(series_obj)
    c.pyapi.decref(arr_obj)
    return native_val.value
示例#2
0
def unbox_series(typ, val, c):
    arr_obj = c.pyapi.object_getattr_string(val, "values")

    if typ.dtype == string_type:
        native_val = unbox_str_series(string_array_type, arr_obj, c)
    elif typ.dtype == datetime_date_type:
        native_val = unbox_datetime_date_array(typ, val, c)
    else:
        # TODO: error handling like Numba callwrappers.py
        native_val = unbox_array(types.Array(dtype=typ.dtype, ndim=1, layout='C'), arr_obj, c)

    c.pyapi.decref(arr_obj)
    return native_val
示例#3
0
def unbox_series(typ, val, c):
    arr_obj = c.pyapi.object_getattr_string(val, "values")
    series = cgutils.create_struct_proxy(typ)(c.context, c.builder)
    series.data = _unbox_series_data(typ.dtype, typ.data, arr_obj, c).value
    # TODO: other indices
    if typ.index == string_array_type:
        index_obj = c.pyapi.object_getattr_string(val, "index")
        series.index = unbox_str_series(string_array_type, index_obj, c).value
    if typ.is_named:
        name_obj = c.pyapi.object_getattr_string(val, "name")
        series.name = numba.unicode.unbox_unicode_str(
            string_type, name_obj, c).value
    # TODO: handle index and name
    c.pyapi.decref(arr_obj)
    return NativeValue(series._getvalue())
示例#4
0
def _unbox_series_data(dtype, data_typ, arr_obj, c):
    if data_typ == string_array_type:
        return unbox_str_series(string_array_type, arr_obj, c)
    elif dtype == datetime_date_type:
        return unbox_datetime_date_array(data_typ, arr_obj, c)
    elif data_typ == list_string_array_type:
        return _unbox_array_list_str(arr_obj, c)
    elif data_typ == string_array_split_view_type:
        # XXX dummy unboxing to avoid errors in _get_dataframe_data()
        out_view = c.context.make_helper(c.builder, string_array_split_view_type)
        return NativeValue(out_view._getvalue())
    elif isinstance(dtype, PDCategoricalDtype):
        return unbox_categorical_array(data_typ, arr_obj, c)

    # TODO: error handling like Numba callwrappers.py
    return unbox_array(data_typ, arr_obj, c)