Skip to content

CLN/DOC: DataFrame.to_parquet supports file-like objects #35235

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 17, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 13 additions & 8 deletions pandas/core/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
IO,
TYPE_CHECKING,
Any,
AnyStr,
Dict,
FrozenSet,
Hashable,
Expand Down Expand Up @@ -2252,11 +2253,11 @@ def to_markdown(
@deprecate_kwarg(old_arg_name="fname", new_arg_name="path")
def to_parquet(
self,
path,
engine="auto",
compression="snappy",
index=None,
partition_cols=None,
path: FilePathOrBuffer[AnyStr],
engine: str = "auto",
compression: Optional[str] = "snappy",
index: Optional[bool] = None,
partition_cols: Optional[List[str]] = None,
**kwargs,
) -> None:
"""
Expand All @@ -2269,9 +2270,12 @@ def to_parquet(

Parameters
----------
path : str
File path or Root Directory path. Will be used as Root Directory
path while writing a partitioned dataset.
path : str or file-like object
If a string, it will be used as Root Directory path
when writing a partitioned dataset. By file-like object,
we refer to objects with a write() method, such as a file handler
(e.g. via builtin open function) or io.BytesIO. The engine
fastparquet does not accept file-like objects.

.. versionchanged:: 1.0.0

Expand All @@ -2298,6 +2302,7 @@ def to_parquet(
partition_cols : list, optional, default None
Column names by which to partition the dataset.
Columns are partitioned in the order they are given.
Must be None if path is not a string.

.. versionadded:: 0.24.0

Expand Down
29 changes: 17 additions & 12 deletions pandas/io/parquet.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
""" parquet compat """

from typing import Any, Dict, Optional
from typing import Any, AnyStr, Dict, List, Optional
from warnings import catch_warnings

from pandas._typing import FilePathOrBuffer
from pandas.compat._optional import import_optional_dependency
from pandas.errors import AbstractMethodError

Expand Down Expand Up @@ -85,10 +86,10 @@ def __init__(self):
def write(
self,
df: DataFrame,
path,
compression="snappy",
path: FilePathOrBuffer[AnyStr],
compression: Optional[str] = "snappy",
index: Optional[bool] = None,
partition_cols=None,
partition_cols: Optional[List[str]] = None,
**kwargs,
):
self.validate_dataframe(df)
Expand Down Expand Up @@ -213,11 +214,11 @@ def read(self, path, columns=None, **kwargs):

def to_parquet(
df: DataFrame,
path,
path: FilePathOrBuffer[AnyStr],
engine: str = "auto",
compression="snappy",
compression: Optional[str] = "snappy",
index: Optional[bool] = None,
partition_cols=None,
partition_cols: Optional[List[str]] = None,
**kwargs,
):
"""
Expand All @@ -226,9 +227,12 @@ def to_parquet(
Parameters
----------
df : DataFrame
path : str
File path or Root Directory path. Will be used as Root Directory path
while writing a partitioned dataset.
path : str or file-like object
If a string, it will be used as Root Directory path
when writing a partitioned dataset. By file-like object,
we refer to objects with a write() method, such as a file handler
(e.g. via builtin open function) or io.BytesIO. The engine
fastparquet does not accept file-like objects.

.. versionchanged:: 0.24.0

Expand All @@ -251,8 +255,9 @@ def to_parquet(
.. versionadded:: 0.24.0

partition_cols : str or list, optional, default None
Column names by which to partition the dataset
Columns are partitioned in the order they are given
Column names by which to partition the dataset.
Columns are partitioned in the order they are given.
Must be None if path is not a string.

.. versionadded:: 0.24.0

Expand Down