def gen_outliers(metrics_iterable, lower_bound=160):
for each_iterator in metrics_iterable:
if each_iterator['processing_time'] > lower_bound:
yield each_iterator
else:
continue
在我这里测试基本也没什么问题,你看看通过没有,如果没通过的话继续讨论。
下面这段是测试用例,上面才是要用的那段代码。
outliers_160 = pd.DataFrame(gen_outliers(test_data, lower_bound=160))
print(outliers_160)
assert len(outliers_160)==1, "wrong 160"
outliers_150 = pd.DataFrame(gen_outliers(test_data, lower_bound=150))
print(outliers_150)
assert len(outliers_150)==2, "wrong 150"
outliers_170 = pd.DataFrame(gen_outliers(test_data, lower_bound=170))
print(outliers_170)
assert len(outliers_170)==0, "wrong 170"
输出的结果是:
job_id processing_time instance_id
0 337 168.8 1349783
job_id processing_time instance_id
0 336 150.8 1346846
1 337 168.8 1349783
Empty DataFrame
Columns: []
Index: []
[Finished in 0.6s]
没有assert出来的异常,应该没啥问题了。