【问题标题】:ArrowIOError occurred reading from BigQuery with google-cloud-bigquery client library (Python)使用 google-cloud-bigquery 客户端库 (Python) 从 BigQuery 读取时发生 ArrowIOError
【发布时间】:2020-11-11 20:38:08
【问题描述】:

我有一个函数可以从查询到 BigQuery 中检索 pandas 数据框,该函数在过去几个月中运行良好。 今天,在没有任何更改的情况下,它在 GoogleColab Notebooks 中停止工作并抛出此异常:

从 BigQuery 读取时发生了 ArrowIOError 类型的异常。 参数:('无法从 BufferReader.',)

我的代码:

def read_from_bigquery_client(bq_client, project_id, sql, curr_func):
  try:
    df = bq_client.query(sql, project=project_id).to_dataframe()
    return df
  except Exception as ex:
    template = "An exception of type {0} occurred reading from BigQuery. Arguments:\n{1!r}\nFunction: {2}"
    message = template.format(type(ex).__name__, ex.args, curr_func)
    print(message)
    return None

客户端验证:

credentials = service_account.Credentials.from_service_account_file(local_cred_filename)
bq_client = bigquery.Client(credentials=credentials,
                            project=credentials.project_id)

我尝试过的查询在直接应用于 BigQuery 时可以完美运行,而且它们之前也如上所述。

感谢您的帮助。

【问题讨论】:

  • 嗨!您能否通过键入:pip freeze 分享 google-cloud-bigquery lib 版本?新版本(1.26.0)今天已经发布,可能会导致问题:pypi.org/project/google-cloud-bigquery/#history
  • 嗨!是的,它在 1.26.0 版本中。问题可能是由于版本更新,因为我刚刚尝试降级到版本 1.21.0 并且它工作正常。

标签: python google-bigquery google-colaboratory pyarrow


【解决方案1】:

google-cloud-bigquery Python 库的new version (1.26.0) 已于 7 月 22 日发布。可能会出现尚未检测到的问题。对应版本的类似问题已在Github上报告,您可以关注更新。另外,也请报告您遇到的错误。

目前ArrowIOError的解决方法是降级google-cloud-bigquery库的版本。

【讨论】:

    【解决方案2】:

    我将 google-cloud-bigquery 的版本降级为 1.24.0 ,错误仍然完好无损。 其他版本是:

    pyarrow==0.11.1
    pandas==0.23.4
    pandas-gbq==0.7.0
    google-cloud-bigquery==1.24.0
    
    

    【讨论】:

      【解决方案3】:

      在升级我的 pandas 包之前我也遇到了同样的问题,显然我从文档中看到,高于 0.29.0 的 pandas 版本可以使用 google-cloud-bigquery

      更新 pandas 的最佳方法是:

      pip3 install --upgrade pandas
      

      【讨论】:

        猜你喜欢
        • 2019-01-07
        • 1970-01-01
        • 2016-04-25
        • 2018-07-02
        • 1970-01-01
        • 1970-01-01
        • 2014-09-22
        • 2015-12-28
        • 1970-01-01
        相关资源
        最近更新 更多