如何识别 Pandas 的 Parquet 后端

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/50760351/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 05:40:08  来源:igfitidea点击:

How to identify Pandas' backend for Parquet

pythonpandasparquet

提问by Cedric H.

I understand that Pandas can read and write to and from Parquet files using different backends: pyarrowand fastparquet.

我知道 Pandas 可以使用不同的后端读写 Parquet 文件:pyarrowfastparquet.

I have a Conda distribution with the Intel distribution and "it works": I can use pandas.DataFrame.to_parquet. However I do not have pyarrowinstalled so I guess that fastparquetis used (which I cannot find either).

我有一个带有 Intel 发行版的 Conda 发行版并且“它有效”:我可以使用pandas.DataFrame.to_parquet. 但是我没有pyarrow安装,所以我想它fastparquet被使用了(我也找不到)。

Is there a way to identify which backend is used?

有没有办法确定使用哪个后端?

采纳答案by EdChum

One method would be to call show_versions()which will list the dependencies (plus other environment stuff):

一种方法是调用show_versions()which 将列出依赖项(以及其他环境内容):

pd.show_versions()

INSTALLED VERSIONS
------------------
commit: None
python: 3.6.0.final.0
python-bits: 64
OS: Windows
OS-release: 7
machine: AMD64
processor: Intel64 Family 6 Model 42 Stepping 7, GenuineIntel
byteorder: little
LC_ALL: None
LANG: None
LOCALE: None.None

pandas: 0.23.0
pytest: 3.0.5
pip: 9.0.3
setuptools: 27.2.0
Cython: 0.25.2
numpy: 1.14.3
scipy: 1.1.0
pyarrow: None
xarray: None
IPython: 5.1.0
sphinx: 1.5.1
patsy: 0.4.1
dateutil: 2.6.0
pytz: 2016.10
blosc: None
bottleneck: 1.2.1
tables: 3.4.3
numexpr: 2.6.5
feather: None
matplotlib: 2.2.2
openpyxl: 2.4.1
xlrd: 1.0.0
xlwt: 1.2.0
xlsxwriter: 0.9.6
lxml: 3.7.2
bs4: 4.5.3
html5lib: 0.9999999
sqlalchemy: 1.1.5
pymysql: None
psycopg2: None
jinja2: 2.9.4
s3fs: None
fastparquet: None
pandas_gbq: None
pandas_datareader: None

Here incidentally I don't have either pyarrowor fastparquetinstalled

这里顺便说一句,我没有任何pyarrowfastparquet安装

Actually you can call pd.io.parquet.get_engine('auto'):

其实你可以打电话pd.io.parquet.get_engine('auto')

In[193]:
pd.io.parquet.get_engine('auto')

---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
<ipython-input-193-929185e5aca8> in <module>()
----> 1 pd.io.parquet.get_engine('auto')

C:\ProgramData\Anaconda3\lib\site-packages\pandas\io\parquet.py in get_engine(engine)
     27             pass
     28 
---> 29         raise ImportError("Unable to find a usable engine; "
     30                           "tried using: 'pyarrow', 'fastparquet'.\n"
     31                           "pyarrow or fastparquet is required for parquet "

ImportError: Unable to find a usable engine; tried using: 'pyarrow', 'fastparquet'.
pyarrow or fastparquet is required for parquet support

As I don't have either installed this raises an ImportError, presumably on your environment this will actually return the installed engine

由于我没有安装这会引发导入错误,大概在您的环境中这实际上会返回已安装的引擎

And after installing fastparquetI now get:

安装后fastparquet我现在得到:

In[194]:
pd.io.parquet.get_engine('auto')

Out[194]: <pandas.io.parquet.FastParquetImpl at 0xf5582b0>

And if we look at the class:

如果我们看一下class

In[202]:
impl = pd.io.parquet.get_engine('auto')
impl.__class__

Out[202]: pandas.io.parquet.FastParquetImpl

it tells us which impl it is.

它告诉我们它是哪个 impl。

If pyarrowis installed one would get:

如果pyarrow安装了一个会得到:

>>> pd.io.parquet.get_engine('auto')
<pandas.io.parquet.PyArrowImpl object at 0xa13fb1ef0>
>>> pd.io.parquet.get_engine('auto').__class__
<class 'pandas.io.parquet.PyArrowImpl'>

回答by ANKIT CHOPADE

Just execute these 2 commands in linux shell/bash

只需在 linux shell/bash 中执行这 2 个命令

pip install pyarrow

pip install fastparquet