Pyarrow.lib.Schema 对比 pyarrow.parquet.Schema

Pyarrow.lib.Schema vs. pyarrow.parquet.Schema

当我尝试跨多个分区的 parquet 文件加载时,由于缺少用空值填充架构的数据,某些架构被无效推断。我认为在 pyarrow.parquet.ParquetDataset 中指定架构可以解决此问题,但我不知道如何构建正确 pyarrow.parquet.Schema 类型的架构。一些示例代码:

import pyarrow as pa
import pa.parquet as pq    
test_schema = pa.schema([pa.field('field1', pa.string()), pa.field('field2', pa.float64())])
paths = ['test_root/partition1/file1.parquet', 'test_root/partition2/file2.parquet']
dataset = pq.ParquetDataset(paths, schema=schema)

错误:

AttributeError: 'pyarrow.lib.Schema' object has no attribute 'to_arrow_schema'

但是我找不到任何关于如何在文档 (https://arrow.apache.org/docs/python/generated/pyarrow.parquet.ParquetDataset.html) 中构建 pyarrow.parquet.Schema 模式的文档,并且只做了一个 pyarrow.lib.Schema 给出了上述错误.

Python 中还没有 API 来构建 Parquet 模式。不过,您可以使用从特定文件中读取的文件(参见 pq.ParquetFile(...).schema)。

您能否在 ARROW JIRA 项目上提出问题以请求在 Python 中构建 Parquet 模式的功能?

https://issues.apache.org/jira