Python 当Dask诊断报告Dask进程已完成时,Dask进程如何不能完成?

Python 当Dask诊断报告Dask进程已完成时,Dask进程如何不能完成?,python,pandas,hdf5,dask,Python,Pandas,Hdf5,Dask,我得到了一个HDF存储,其中一个数据帧为60089424行x 5列。所有列都是分类的,它们都包含相同的值到代码的映射,这有3318655个类别。使用complevel=9和complib='blosc:lz4'压缩HDF存储。它是用format='table'编写的。该文件的磁盘容量为1.1G 我之所以提到这一切,是因为我不知道这是否与我的问题有关 我现在想从数据帧中删除包含频率低于某个阈值的值的行,我想在合理的时间内完成这项工作。我问了一个问题 我最终设法用Dask构建了似乎能在合理时间内完成

我得到了一个HDF存储,其中一个数据帧为60089424行x 5列。所有列都是分类的,它们都包含相同的值到代码的映射,这有3318655个类别。使用
complevel=9
complib='blosc:lz4'
压缩HDF存储。它是用
format='table'
编写的。该文件的磁盘容量为1.1G

我之所以提到这一切,是因为我不知道这是否与我的问题有关

我现在想从数据帧中删除包含频率低于某个阈值的值的行,我想在合理的时间内完成这项工作。我问了一个问题

我最终设法用Dask构建了似乎能在合理时间内完成这项工作的代码(如果这里的问题可以解决,我将用代码回答我自己的问题)。但有一个大问题。代码不会终止。在调用
compute()。它还完成
compute()
,如完成的进度条所示。但它仍然存在。我从不执行下一行(
print(f'{time\u to\u display()}:删除的带有低频字的行)

现在…我真的不知道为什么会这样。事实上,我几乎是在胡思乱想。你能给我解释一下为什么
compute()
-调用显示为已完成但没有完成吗

import time
import dask.dataframe as ddf
import dask
import numpy as np
import pandas as pd


def time_to_display():
    return time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(time.time()))



hdfstore_filename =  '<the HDF file>'
threshold = 100

print(f'{time_to_display()}: filtering data for low frequency words')
print(f'file = {hdfstore_filename}.h5')

store = pd.HDFStore(f'{hdfstore_filename}.h5')
df = store.select(key='/ngrams')

print(f'{time_to_display()}: data loaded')

unique, counts = np.unique(df.values.ravel(), return_counts=True)
print(f'{time_to_display()}: gathered frequencies of words [1]')

d = dict(zip(unique, counts))
print(f'{time_to_display()}: gathered frequencies of words [2]')

to_remove = [k for k, v in d.items() if v < threshold]
print(f'{time_to_display()}: gathered indices of values to remove')


df_dask = ddf.from_pandas(df, chunksize=1000000) # results in 60 chunks for this data
print(f'{time_to_display()}: df_dask created')

mask = df_dask.isin(to_remove)
print(f'{time_to_display()}: mask created')

column_mask = (~mask).all(axis=1)
print(f'{time_to_display()}: column_mask created')

df_dask = df_dask[column_mask]
print(f'{time_to_display()}: df_dask filtered')

df_dask.visualize(filename='log/df_dask', format='pdf')
print(f'{time_to_display()}: computation graph rendered')

from dask.diagnostics import ProgressBar

with ProgressBar():
    df_out = dask.compute(df_dask)[0]
print(f'{time_to_display()}: dropped rows with low frequency words')

df_out.to_hdf(f'{hdfstore_filename}_filtered_complete.h5', 'ngrams', complevel=9,
          complib='blosc:lz4', format='table')
print(f'{time_to_display()}: store written')

store.close()
我让程序再运行30分钟,但没有出现新消息

编辑
我现在使用同一个数据集的一个版本运行此操作,但有一个区别:所有列都有自己独特的分类编码。这次进度条报告完成与下一条正在打印的进度消息之间的时间差“只有”15分钟。所以关键是分类编码。知道为什么吗

2018-12-05 13:00:46: filtering data for low frequency words
file = data/5grams_wiki_00/5grams_wiki_00_cat.h5
2018-12-05 13:01:34: data loaded
2018-12-05 13:11:00: gathered frequencies of words [1]
2018-12-05 13:11:01: gathered frequencies of words [2]
2018-12-05 13:11:02: gathered indices of values to remove
2018-12-05 13:11:19: df_dask created
2018-12-05 13:11:31: mask created
2018-12-05 13:11:31: column_mask created
2018-12-05 13:11:31: df_dask filtered
2018-12-05 13:11:31: computation graph rendered
[########################################] | 100% Completed |  5min 52.3s
2018-12-05 13:28:49: dropped rows with low frequency words
2018-12-05 13:31:05: store written

我现在使用同一个数据集的一个版本运行此操作,但有一个区别:所有列都有自己独特的分类编码。这次进度条报告完成与下一条正在打印的进度消息之间的时间差“只有”15分钟。所以关键是分类编码。知道为什么吗?
2018-12-05 13:00:46: filtering data for low frequency words
file = data/5grams_wiki_00/5grams_wiki_00_cat.h5
2018-12-05 13:01:34: data loaded
2018-12-05 13:11:00: gathered frequencies of words [1]
2018-12-05 13:11:01: gathered frequencies of words [2]
2018-12-05 13:11:02: gathered indices of values to remove
2018-12-05 13:11:19: df_dask created
2018-12-05 13:11:31: mask created
2018-12-05 13:11:31: column_mask created
2018-12-05 13:11:31: df_dask filtered
2018-12-05 13:11:31: computation graph rendered
[########################################] | 100% Completed |  5min 52.3s
2018-12-05 13:28:49: dropped rows with low frequency words
2018-12-05 13:31:05: store written