Skip to content

Commit 212c651

Browse files
Backport PR #48995 on branch 1.5.x (REGR: to_parquet raising with bytes filename) (#49061)
Backport PR #48995: REGR: to_parquet raising with bytes filename Co-authored-by: Patrick Hoefler <[email protected]>
1 parent daf465c commit 212c651

File tree

3 files changed

+13
-0
lines changed

3 files changed

+13
-0
lines changed

doc/source/whatsnew/v1.5.1.rst

+1
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ Fixed regressions
8585
- Fixed Regression in :meth:`DataFrameGroupBy.apply` when user defined function is called on an empty dataframe (:issue:`47985`)
8686
- Fixed regression in :meth:`DataFrame.apply` when passing non-zero ``axis`` via keyword argument (:issue:`48656`)
8787
- Fixed regression in :meth:`Series.groupby` and :meth:`DataFrame.groupby` when the grouper is a nullable data type (e.g. :class:`Int64`) or a PyArrow-backed string array, contains null values, and ``dropna=False`` (:issue:`48794`)
88+
- Fixed regression in :meth:`DataFrame.to_parquet` raising when file name was specified as ``bytes`` (:issue:`48944`)
8889
- Fixed regression in :class:`ExcelWriter` where the ``book`` attribute could no longer be set; however setting this attribute is now deprecated and this ability will be removed in a future version of pandas (:issue:`48780`)
8990

9091
.. ---------------------------------------------------------------------------

pandas/io/parquet.py

+2
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,8 @@ def write(
186186
and isinstance(path_or_handle.name, (str, bytes))
187187
):
188188
path_or_handle = path_or_handle.name
189+
if isinstance(path_or_handle, bytes):
190+
path_or_handle = path_or_handle.decode()
189191

190192
try:
191193
if partition_cols is not None:

pandas/tests/io/test_parquet.py

+10
Original file line numberDiff line numberDiff line change
@@ -1182,3 +1182,13 @@ def test_close_file_handle_on_read_error(self):
11821182
read_parquet(path, engine="fastparquet")
11831183
# The next line raises an error on Windows if the file is still open
11841184
pathlib.Path(path).unlink(missing_ok=False)
1185+
1186+
def test_bytes_file_name(self, engine):
1187+
# GH#48944
1188+
df = pd.DataFrame(data={"A": [0, 1], "B": [1, 0]})
1189+
with tm.ensure_clean("test.parquet") as path:
1190+
with open(path.encode(), "wb") as f:
1191+
df.to_parquet(f)
1192+
1193+
result = read_parquet(path, engine=engine)
1194+
tm.assert_frame_equal(result, df)

0 commit comments

Comments
 (0)