pyarrow 从 S3 性能混淆中读取镶木地板

pyarrow reading parquet from S3 performance confusions

我在 AWS S3 中有一个 Parquet 文件。我想将它读入 Pandas DataFrame。我有两种方法可以做到这一点。

1)
import pyarrow.parquet as pq
table = pq.read_table("s3://tpc-h-parquet/lineitem/part0.snappy.parquet") (takes 1 sec)
pandas_table = table.to_pandas() ( takes 1 sec !!! )
2)
import pandas as pd
table = pd.read_parquet("s3://tpc-h-parquet/lineitem/part0.snappy.parquet") (takes 2 sec)

我怀疑选项 2 实际上只是在幕后执行选项 1。

我将 Parquet 文件读入 Pandas 的最快方法是什么?

你是对的。选项 2 只是引擎盖下的选项 1。

What is the fastest way for me to read a Parquet file into Pandas?

选项 1 和选项 2 可能都足够好。但是,如果你想剃掉每一点,你可能需要更深一层,这取决于你的 pyarrow 版本。事实证明,选项 1 实际上也只是一个代理,在本例中是数据集 API:

import pyarrow.dataset as ds
dataset = ds.dataset("s3://tpc-h-parquet/lineitem/part0.snappy.parquet")
table = dataset.to_table(use_threads=True)
df = table.to_pandas()

对于 >= 4 和 < 7 的 pyarrow 版本,您通常可以使用异步扫描器在 S3 上获得更好的性能:

import pyarrow.dataset as ds
dataset = ds.dataset("s3://tpc-h-parquet/lineitem/part0.snappy.parquet")
table = dataset.to_table(use_threads=True, use_async=True)
df = table.to_pandas()

在 pyarrow 版本 7 中,异步扫描器是默认设置,因此您可以再次简单地使用 pd.read_parquet("s3://tpc-h-parquet/lineitem/part0.snappy.parquet")