我经常遇到的错误是
>> dd.read_csv('/tmp/*.csv', parse_dates=['start_time', 'end_time'])
Traceback (most recent call last):
...
File "/Users/brettnaul/venvs/model37/lib/python3.6/site-packages/dask/dataframe/io/csv.py", line 163, in coerce_dtypes
raise ValueError(msg)
ValueError: Mismatched dtypes found in `pd.read_csv`/`pd.read_table`.
The following columns failed to properly parse as dates:
- start_time
- end_time
This is usually due to an invalid value in that column. To
diagnose and fix it's recommended to drop these columns from the
`parse_dates` keyword, and manually convert them to dates later
using `dd.to_datetime`.
显然我的一个文件格式错误,但哪个文件?到目前为止,我提出的最佳解决方案是:
- 在 IPython 中重新运行相同的命令
- %调试魔法
- 将原始 CSV 文本的样本打印到控制台
- 找到一个独特的文本和 grep 直到我找出有问题的文件
这对我来说似乎非常迂回,但除非我遗漏了一些明显的东西,否则追溯中似乎没有任何其他识别信息。有没有更好的方法来找出哪个文件失败了?使用collection=False
和检查Delayed
对象也可能有效,但我不确定要寻找什么。有什么方法可以使引发的异常包含有关问题发生位置的一些提示,或者一旦read_csv
调用该信息就无法获得?