Skip to content
This repository was archived by the owner on Feb 2, 2024. It is now read-only.

Commit 4a6d246

Browse files
author
Ehsan Totoni
committed
refactor _unbox_series_data to use for both series and df
1 parent c1d7e1e commit 4a6d246

1 file changed

Lines changed: 18 additions & 21 deletions

File tree

hpat/hiframes/boxing.py

Lines changed: 18 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -229,21 +229,9 @@ def codegen(context, builder, sig, args):
229229
series_obj = c.pyapi.object_getattr_string(dataframe.parent, col_name)
230230
arr_obj = c.pyapi.object_getattr_string(series_obj, "values")
231231

232-
if data_typ == string_array_type:
233-
native_val = unbox_str_series(string_array_type, arr_obj, c)
234-
elif data_typ == string_array_split_view_type:
235-
# XXX dummy unboxing to avoid errors in _get_dataframe_data()
236-
out_view = context.make_helper(builder, string_array_split_view_type)
237-
native_val = NativeValue(out_view._getvalue())
238-
elif data_typ == list_string_array_type:
239-
native_val = _unbox_array_list_str(arr_obj, c)
240-
else:
241-
dtype = data_typ.dtype
242-
if isinstance(dtype, PDCategoricalDtype):
243-
native_val = unbox_categorical_array(data_typ, arr_obj, c)
244-
else:
245-
# TODO: error handling like Numba callwrappers.py
246-
native_val = unbox_array(types.Array(dtype, 1, 'C'), arr_obj, c)
232+
# TODO: support column of tuples?
233+
native_val = _unbox_series_data(
234+
data_typ.dtype, data_typ, arr_obj, c)
247235

248236
c.pyapi.decref(series_obj)
249237
c.pyapi.decref(arr_obj)
@@ -262,19 +250,28 @@ def codegen(context, builder, sig, args):
262250
def unbox_series(typ, val, c):
263251
arr_obj = c.pyapi.object_getattr_string(val, "values")
264252
series = cgutils.create_struct_proxy(typ)(c.context, c.builder)
265-
series.data = _unbox_series_data(typ.dtype, typ.data, val, c, arr_obj)
253+
series.data = _unbox_series_data(typ.dtype, typ.data, arr_obj, c).value
266254
# TODO: handle index and name
267255
c.pyapi.decref(arr_obj)
268256
return NativeValue(series._getvalue())
269257

270-
def _unbox_series_data(dtype, data_typ, val, c, arr_obj):
271-
if dtype == string_type:
272-
return unbox_str_series(string_array_type, arr_obj, c).value
258+
259+
def _unbox_series_data(dtype, data_typ, arr_obj, c):
260+
if data_typ == string_array_type:
261+
return unbox_str_series(string_array_type, arr_obj, c)
273262
elif dtype == datetime_date_type:
274-
return unbox_datetime_date_array(data_typ, val, c).value
263+
return unbox_datetime_date_array(data_typ, arr_obj, c)
264+
elif data_typ == list_string_array_type:
265+
return _unbox_array_list_str(arr_obj, c)
266+
elif data_typ == string_array_split_view_type:
267+
# XXX dummy unboxing to avoid errors in _get_dataframe_data()
268+
out_view = c.context.make_helper(c.builder, string_array_split_view_type)
269+
return NativeValue(out_view._getvalue())
270+
elif isinstance(dtype, PDCategoricalDtype):
271+
return unbox_categorical_array(data_typ, arr_obj, c)
275272

276273
# TODO: error handling like Numba callwrappers.py
277-
return unbox_array(types.Array(dtype, 1, 'C'), arr_obj, c).value
274+
return unbox_array(data_typ, arr_obj, c)
278275

279276

280277
@box(SeriesType)

0 commit comments

Comments
 (0)