如何在Polars中忽略PyArrow时间戳转换错误?
解决Polars读取Delta表时的时间戳精度丢失错误
直接通过pl.read_delta的pyarrow_options传递参数
Polars的read_delta底层依赖PyArrow处理Delta表读取,你可以通过pyarrow_options传入PyArrow的cast_options参数,设置safe=False来跳过精度检查,和Pandas的safe=False效果一致:
import polars as pl df = pl.read_delta( "path/to/your/delta_table", pyarrow_options={ "cast_options": {"safe": False} } )
备选方案:先通过PyArrow读取再转Polars
如果上述参数不生效,可以先使用PyArrow直接读取Delta表并设置safe=False,再转换为Polars DataFrame:
import pyarrow.dataset as ds import polars as pl # PyArrow读取Delta表,跳过精度检查 arrow_table = ds.dataset("path/to/your/delta_table", format="delta").to_table( cast_options={"safe": False} ) # 转换为Polars DataFrame df = pl.from_arrow(arrow_table)
内容的提问来源于stack exchange,提问作者user23406368
相关产品推荐
相关产品推荐

