从延迟的 dask 数组创建 dask 数据框

Creating dask dataframe from delayed dask arrays

我有一个存储在 dask_arr_ls 中的延迟 dask 数组列表,我想将其转换为 dask 数据帧。这是我的管道的框架:

def simulate_device_data(num_id):
    # create data for unknown number of timestamps
    data_ls = [unknown_qty*[num_id, time, lon, lat]]
    device_arr = np.stack(data_ls)
    device_dask_arr = da.from_array(device_arr, chunks=device_arr.size)
    return device_dask_arr

    
dask_arr_ls = []
for i_device in range(n_devices):
    i_dask_arr = delayed(simulate_device_data)(i_device)
    dask_arr_ls.append(i_darr)
    
dask_arr_ls = [da.from_delayed(i_dask_arr, shape=(np.nan, 4), dtype=float) 
               for i_dask_arr in dask_arr_ls]
ddf = dd.concat([dd.from_dask_array(i_darr) for i_darr in darr_ls])
ddf.columns = ["num_id", "t", "lon", "lat"]
ddf.compute()

compute() 产生以下错误消息:

ValueError: DataFrame constructor not properly called!

我做错了什么?

我从来没有弄清楚我上面的代码有什么错误。我怀疑我以某种方式滥用了 delayed 。我按如下方式修改了管道以使其正常工作。

def simulate_device_data(num_id):
    # create data for unknown number of timestamps
    data_ls = [unknown_qty*[num_id, time, lon, lat]]
    device_arr = np.stack(data_ls)
    device_df = pd.DataFrame(device_arr)
    return device_df

    
df_ls = []
for i_device in range(n_devices):
    i_df = delayed(simulate_device_data)(i_device)
    df_ls.append(i_df)
    
archetype_df = pd.DataFrame(None, columns=["name", "num_id", "t", "lon", "lat"])
archetype_df = archetype_df.astype({"name": "object", "num_id": "int64", "t": "datetime64[ns]", 
                                    "lon": "float64", "lat": "float64"},
                                   copy=False)
ddf = dd.from_delayed(df_ls, meta=archetype_df)
ddf.compute()