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

Commit 7e204e4

Browse files
committed
Change boxing of DataFrame.data
1 parent e059436 commit 7e204e4

1 file changed

Lines changed: 6 additions & 27 deletions

File tree

sdc/hiframes/boxing.py

Lines changed: 6 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -205,58 +205,37 @@ def box_dataframe(typ, val, c):
205205
n_cols = len(typ.columns)
206206
col_names = typ.columns
207207
arr_typs = typ.data
208-
dtypes = [a.dtype for a in arr_typs] # TODO: check Categorical
209208

210209
dataframe = cgutils.create_struct_proxy(typ)(context, builder, value=val)
211210

212-
# df unboxed from Python
213-
has_parent = cgutils.is_not_null(builder, dataframe.parent)
214-
215211
pyapi = c.pyapi
216212
# gil_state = pyapi.gil_ensure() # acquire GIL
217213

218214
mod_name = context.insert_const_string(c.builder.module, "pandas")
219215
class_obj = pyapi.import_module_noblock(mod_name)
220216
df_dict = pyapi.dict_new()
221217

222-
for i, cname, arr_typ, dtype in zip(range(n_cols), col_names, arr_typs, dtypes):
218+
for i, cname, arr_typ in zip(range(n_cols), col_names, arr_typs):
223219
# df['cname'] = boxed_arr
224220
# TODO: datetime.date, DatetimeIndex?
225221
name_str = context.insert_const_string(c.builder.module, cname)
226222
cname_obj = pyapi.string_from_string(name_str)
227223

228224
col_loc = typ.column_loc[cname]
229225
type_id, col_id = col_loc.type_id, col_loc.col_id
230-
list_type = types.List(arr_typs[i])
231226

232227
# dataframe.data looks like a tuple(list(array))
233228
# e.g. ([array(int64, 1d, C), array(int64, 1d, C)], [array(float64, 1d, C)])
234-
229+
list_type = types.List(arr_typ)
235230
# extracting list from the tuple
236231
list_val = builder.extract_value(dataframe.data, type_id)
237-
typ_arrs = listobj.ListInstance(context, builder, list_type, list_val)
238232
# getting array from the list to box it then
239-
arr = typ_arrs.getitem(col_id)
240-
typ_arrs.incref_value(arr)
241-
242-
if dtype == string_type:
243-
arr_obj = box_str_arr(arr_typ, arr, c)
244-
elif isinstance(dtype, PDCategoricalDtype):
245-
arr_obj = box_categorical_array(arr_typ, arr, c)
246-
# context.nrt.incref(builder, arr_typ, arr)
247-
elif dtype == types.List(string_type):
248-
arr_obj = box_list(list_string_array_type, arr, c)
249-
# context.nrt.incref(builder, arr_typ, arr) # TODO required?
250-
# pyapi.print_object(arr_obj)
251-
else:
252-
arr_obj = box_array(arr_typ, arr, c)
253-
# TODO: is incref required?
254-
# context.nrt.incref(builder, arr_typ, arr)
233+
arrays_list_obj = box_list(list_type, list_val, c)
234+
# PyList_GetItem returns borrowed reference
235+
arr_obj = pyapi.list_getitem(arrays_list_obj, col_id)
255236
pyapi.dict_setitem(df_dict, cname_obj, arr_obj)
256237

257-
if c.context.enable_nrt:
258-
c.context.nrt.decref(c.builder, list_type, list_val)
259-
pyapi.decref(arr_obj)
238+
# pyapi.decref(arrays_list_obj)
260239
pyapi.decref(cname_obj)
261240

262241
df_obj = pyapi.call_method(class_obj, "DataFrame", (df_dict,))

0 commit comments

Comments
 (0)