0
# Init
import time
import pandas as pd
import numpy as np
from dask.distributed import Client
client = Client()
# Publish data
dataset_name = 'my_dataset'
df_my_dataset = pd.DataFrame(np.ones((2,3)), dtype=np.float32)
client.publish_dataset(df_my_dataset, name=dataset_name)

在那里:

In [13]: client.list_datasets()                                                                                                           
Out[13]: ('my_dataset',)

为 dask 创建提交函数。在这里,我想按名称访问已发布的数据集:

# submit function
def get_gate1_rows(df_from_submit):
    return df_from_submit.mean()
    # return df.mean() + my_dataset.mean() #### <<<<<<< How to do this?

最后提交:

# Submit code
df_zeros = np.zeros((2,3), dtype=np.float32)
future = client.submit(get_gate1_rows, df_zeros)
time.sleep(2)
result = future.result()

这会产生 - 但应该是0.5

In [41]: result                                                                                                                           
Out[41]: 0.0

那么我怎样才能published datasetdask工作中访问呢?

4

1 回答 1

2

要访问任务中已发布的数据集,您需要get_client

def get_gate1_rows(df_from_submit):
    client = distributed.get_client()
    my_dataset = client.get_dataset('my_dataset')
    return df_from_submit.mean() + my_dataset.mean()

(答案是三个 1,因为 df_zeros.mean()->0, df_my_dataset.mean()->1,1,1)

于 2020-05-14T18:04:39.637 回答