11""" parquet compat """
22
3- from typing import Any , Dict , Optional
3+ from typing import Any , AnyStr , Dict , List , Optional
44from warnings import catch_warnings
55
6+ from pandas ._typing import FilePathOrBuffer
67from pandas .compat ._optional import import_optional_dependency
78from pandas .errors import AbstractMethodError
89
@@ -85,10 +86,10 @@ def __init__(self):
8586 def write (
8687 self ,
8788 df : DataFrame ,
88- path ,
89- compression = "snappy" ,
89+ path : FilePathOrBuffer [ AnyStr ] ,
90+ compression : Optional [ str ] = "snappy" ,
9091 index : Optional [bool ] = None ,
91- partition_cols = None ,
92+ partition_cols : Optional [ List [ str ]] = None ,
9293 ** kwargs ,
9394 ):
9495 self .validate_dataframe (df )
@@ -213,11 +214,11 @@ def read(self, path, columns=None, **kwargs):
213214
214215def to_parquet (
215216 df : DataFrame ,
216- path ,
217+ path : FilePathOrBuffer [ AnyStr ] ,
217218 engine : str = "auto" ,
218- compression = "snappy" ,
219+ compression : Optional [ str ] = "snappy" ,
219220 index : Optional [bool ] = None ,
220- partition_cols = None ,
221+ partition_cols : Optional [ List [ str ]] = None ,
221222 ** kwargs ,
222223):
223224 """
@@ -226,9 +227,12 @@ def to_parquet(
226227 Parameters
227228 ----------
228229 df : DataFrame
229- path : str
230- File path or Root Directory path. Will be used as Root Directory path
231- while writing a partitioned dataset.
230+ path : str or file-like object
231+ If a string, it will be used as Root Directory path
232+ when writing a partitioned dataset. By file-like object,
233+ we refer to objects with a write() method, such as a file handler
234+ (e.g. via builtin open function) or io.BytesIO. The engine
235+ fastparquet does not accept file-like objects.
232236
233237 .. versionchanged:: 0.24.0
234238
@@ -251,8 +255,9 @@ def to_parquet(
251255 .. versionadded:: 0.24.0
252256
253257 partition_cols : str or list, optional, default None
254- Column names by which to partition the dataset
255- Columns are partitioned in the order they are given
258+ Column names by which to partition the dataset.
259+ Columns are partitioned in the order they are given.
260+ Must be None if path is not a string.
256261
257262 .. versionadded:: 0.24.0
258263
0 commit comments