Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit a816033

Browse files
committedOct 17, 2020
TYP: return type hints
1 parent e53ed63 commit a816033

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed
 

‎pandas/core/frame.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2295,7 +2295,7 @@ def to_parquet(
22952295
partition_cols: Optional[List[str]] = None,
22962296
storage_options: StorageOptions = None,
22972297
**kwargs,
2298-
) -> None:
2298+
) -> Optional[bytes]:
22992299
"""
23002300
Write a DataFrame to the binary parquet format.
23012301

‎pandas/io/parquet.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -246,19 +246,21 @@ def to_parquet(
246246
storage_options: StorageOptions = None,
247247
partition_cols: Optional[List[str]] = None,
248248
**kwargs,
249-
):
249+
) -> Optional[bytes]:
250250
"""
251251
Write a DataFrame to the parquet format.
252252
253253
Parameters
254254
----------
255255
df : DataFrame
256-
path : str or file-like object
256+
path : str or file-like object, default None
257257
If a string, it will be used as Root Directory path
258258
when writing a partitioned dataset. By file-like object,
259259
we refer to objects with a write() method, such as a file handle
260260
(e.g. via builtin open function) or io.BytesIO. The engine
261-
fastparquet does not accept file-like objects.
261+
fastparquet does not accept file-like objects. If path is None,
262+
frame is written to an io.BytesIO object and a bytes object with
263+
the contents of the buffer is returned.
262264
263265
.. versionchanged:: 0.24.0
264266
@@ -304,7 +306,10 @@ def to_parquet(
304306
partition_cols = [partition_cols]
305307
impl = get_engine(engine)
306308

307-
path_or_buf = io.BytesIO() if path is None else path
309+
if path is None:
310+
path_or_buf = io.BytesIO()
311+
else:
312+
path_or_buf = path
308313

309314
impl.write(
310315
df,
@@ -318,6 +323,8 @@ def to_parquet(
318323

319324
if path is None:
320325
return path_or_buf.getvalue()
326+
else:
327+
return None
321328

322329

323330
def read_parquet(path, engine: str = "auto", columns=None, **kwargs):

0 commit comments

Comments
 (0)
Please sign in to comment.