Google BigQuery Schema 与使用 load_table_from_dataframe 的数字数据类型发生冲突(pyarrow 错误)
Google BigQuery Schema conflict (pyarrow error) with Numeric data type using load_table_from_dataframe
当我将数字数据(int64 或 float64)从 Pandas 数据帧上传到 "Numeric" Google BigQuery 数据时出现以下错误类型:
pyarrow.lib.ArrowInvalid: Got bytestring of length 8 (expected 16)
我试图从 Pandas 数据帧更改 'tt' 字段的数据类型但没有结果:
df_data_f['tt'] = df_data_f['tt'].astype('float64')
和
df_data_f['tt'] = df_data_f['tt'].astype('int64')
使用架构:
job_config.schema = [
...
bigquery.SchemaField('tt', 'NUMERIC')
...]
阅读本文 google-cloud-python issues report 我得到:
NUMERIC = pyarrow.decimal128(38, 9)
因此 "Numeric" Google BigQuery 数据类型使用比“float64”或“int64”更多的字节,这就是为什么 pyarrow 无法匹配数据类型。
我有:
Python 3.6.4
pandas 1.0.3
pyarrow 0.17.0
google-cloud-bigquery 1.24.0
我不确定这是否是最佳解决方案,但我通过更改数据类型解决了这个问题:
import decimal
...
df_data_f['tt'] = df_data_f['tt'].astype(str).map(decimal.Decimal)
当我将数字数据(int64 或 float64)从 Pandas 数据帧上传到 "Numeric" Google BigQuery 数据时出现以下错误类型:
pyarrow.lib.ArrowInvalid: Got bytestring of length 8 (expected 16)
我试图从 Pandas 数据帧更改 'tt' 字段的数据类型但没有结果:
df_data_f['tt'] = df_data_f['tt'].astype('float64')
和
df_data_f['tt'] = df_data_f['tt'].astype('int64')
使用架构:
job_config.schema = [
...
bigquery.SchemaField('tt', 'NUMERIC')
...]
阅读本文 google-cloud-python issues report 我得到:
NUMERIC = pyarrow.decimal128(38, 9)
因此 "Numeric" Google BigQuery 数据类型使用比“float64”或“int64”更多的字节,这就是为什么 pyarrow 无法匹配数据类型。
我有:
Python 3.6.4
pandas 1.0.3
pyarrow 0.17.0
google-cloud-bigquery 1.24.0
我不确定这是否是最佳解决方案,但我通过更改数据类型解决了这个问题:
import decimal
...
df_data_f['tt'] = df_data_f['tt'].astype(str).map(decimal.Decimal)