Pandas GenericGBQException [英] Pandas GenericGBQException

查看:41
本文介绍了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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆