【发布时间】:2020-12-28 11:44:33
【问题描述】:
我在尝试将 pandas 数据帧转换为 pyarrow 表并写入 parquet 数据集时收到 out of bounds timestamp 错误消息。从一些研究来看,我相信这似乎是熊猫使用纳秒精度和 pyarrow 只能解释到毫秒精度的结果。
import cx_Oracle
import pandas as pd
import pyarrow as pa
import pyarrow.parquet as pq
connection = cx_Oracle.connect(os.getenv('USER'), os.getenv('__OPW'), os.getenv('DB_SERVICE'))
gen = pd.read_sql('SELECT * FROM myschema.mytable where rownum < 10001', con=connection, chunksize=1_000)
for df in gen:
table = pa.Table.from_pandas(df)
pq.write_to_dataset(table, root_path='/tmp/dataset', partition_cols=['my_part_col'])
ArrowInvalid: Casting from timestamp[us] to timestamp[ns] would result in out of bounds timestamp: 253402214400000000
当我注释掉最后一行时:
# pq.write_to_dataset(table, root_path='/tmp/dataset', partition_cols=['my_part_col'])
...重新运行,错误信息不再产生,所以它可能是从pyarrow table 到parquet的转换发生的。
是否有已知的解决方法?
谢谢。
更新:
这是完整的回溯...
Traceback (most recent call last):
File "<stdin>", line 3, in <module>
File "/Users/myusername/miniconda3/envs/py38/lib/python3.8/site-packages/pyarrow/parquet.py", line 1754, in write_to_dataset
df = table.to_pandas()
File "pyarrow/array.pxi", line 715, in pyarrow.lib._PandasConvertible.to_pandas
File "pyarrow/table.pxi", line 1565, in pyarrow.lib.Table._to_pandas
File "/Users/myusername/miniconda3/envs/py38/lib/python3.8/site-packages/pyarrow/pandas_compat.py", line 779, in table_to_blockmanager
blocks = _table_to_blocks(options, table, categories, ext_columns_dtypes)
File "/Users/myusername/miniconda3/envs/py38/lib/python3.8/site-packages/pyarrow/pandas_compat.py", line 1114, in _table_to_blocks
result = pa.lib.table_to_blocks(options, block_table, categories,
File "pyarrow/table.pxi", line 1028, in pyarrow.lib.table_to_blocks
File "pyarrow/error.pxi", line 84, in pyarrow.lib.check_status
pyarrow.lib.ArrowInvalid: Casting from timestamp[us] to timestamp[ns] would result in out of bounds timestamp: 253402214400000000
【问题讨论】:
-
请将回溯发布到异常,以便我们知道它实际发生的位置。
标签: python pandas dataframe parquet pyarrow