10
10
def get_engine (engine ):
11
11
""" return our implementation """
12
12
13
- if engine is None :
13
+ if engine is 'auto' :
14
14
engine = get_option ('io.parquet.engine' )
15
15
16
+ if engine is 'auto' :
17
+ # try engines in this order
18
+ try :
19
+ return PyArrowImpl ()
20
+ except ImportError :
21
+ pass
22
+
23
+ try :
24
+ return FastParquetImpl ()
25
+ except ImportError :
26
+ pass
27
+
16
28
if engine not in ['pyarrow' , 'fastparquet' ]:
17
29
raise ValueError ("engine must be one of 'pyarrow', 'fastparquet'" )
18
30
@@ -98,7 +110,7 @@ def read(self, path):
98
110
return self .api .ParquetFile (path ).to_pandas ()
99
111
100
112
101
- def to_parquet (df , path , engine = None , compression = 'snappy' , ** kwargs ):
113
+ def to_parquet (df , path , engine = 'auto' , compression = 'snappy' , ** kwargs ):
102
114
"""
103
115
Write a DataFrame to the parquet format.
104
116
@@ -107,10 +119,10 @@ def to_parquet(df, path, engine=None, compression='snappy', **kwargs):
107
119
df : DataFrame
108
120
path : string
109
121
File path
110
- engine : str, optional
111
- The parquet engine, one of {'pyarrow ', 'fastparquet'}
112
- If None, will use the option: ` io.parquet.engine`, which
113
- defaults to 'pyarrow'
122
+ engine : {'auto', 'pyarrow', 'fastparquet'}, default 'auto'
123
+ Parquet reader library to use. If 'auto ', then the option
124
+ ' io.parquet.engine' is used. If 'auto', then the first
125
+ library to be installed is used.
114
126
compression : str, optional, default 'snappy'
115
127
compression method, includes {'gzip', 'snappy', 'brotli'}
116
128
kwargs
@@ -156,7 +168,7 @@ def to_parquet(df, path, engine=None, compression='snappy', **kwargs):
156
168
return impl .write (df , path , compression = compression )
157
169
158
170
159
- def read_parquet (path , engine = None , ** kwargs ):
171
+ def read_parquet (path , engine = 'auto' , ** kwargs ):
160
172
"""
161
173
Load a parquet object from the file path, returning a DataFrame.
162
174
@@ -166,9 +178,10 @@ def read_parquet(path, engine=None, **kwargs):
166
178
----------
167
179
path : string
168
180
File path
169
- engine : str, optional
170
- The parquet engine, one of {'pyarrow', 'fastparquet'}
171
- if None, will use the option: `io.parquet.engine`
181
+ engine : {'auto', 'pyarrow', 'fastparquet'}, default 'auto'
182
+ Parquet reader library to use. If 'auto', then the option
183
+ 'io.parquet.engine' is used. If 'auto', then the first
184
+ library to be installed is used.
172
185
kwargs are passed to the engine
173
186
174
187
Returns
0 commit comments