Pandas GenericGBQException

老子叫甜甜 提交于 2019-12-31 05:43:12

问题


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.

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.


回答1:


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?)

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



来源:https://stackoverflow.com/questions/35173847/pandas-genericgbqexception

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!