本文介绍了 pandas GenericGBQException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试使用try/except查询BigQuery表,有时查询可能不正确,在这种情况下,pandas会引发GenericGBQException错误.

I'm trying to use try/except to query BigQuery tables, sometimes the query may not be correct in which case pandas raises a GenericGBQException error.

我的问题是,尝试处理此错误时,我未获得名称"GenericGBQException"的定义,示例代码如下:

My problem is I get name 'GenericGBQException' is not defined when trying to handle this error, example code below:

try:
    df = pd.read_gbq(query, projID)
    query_fail = 0
except GenericGBQException:
    query_fail = 1
if query_fail == 1:
    do some stuff

尽管很不理想,我仍然可以捕获所有异常.

I can get by with catching all exceptions though obviously it's not ideal.

推荐答案

我怀疑您想抓住pd.GenericGBQException. (或者gbq.GenericGBQException -这取决于您的导入.是否要导入定义要捕获的异常的模块?)

I suspect you want to catch pd.GenericGBQException. (Or perhaps gbq.GenericGBQException -- it depends on your imports. Are you importing the module that defines the exception you're trying to catch?)

此外,考虑捕获PandasError,这是程序包中所有异常的基类: https://github.com/pydata/pandas/blob/master/pandas/io/gbq.py#L85

Also, consider catching PandasError, the base class of all exceptions from the package: https://github.com/pydata/pandas/blob/master/pandas/io/gbq.py#L85

这篇关于 pandas GenericGBQException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-28 08:36
查看更多