Skip to content

Commit 56d82a9

Browse files
authored
REGR: to_parquet raising with bytes filename (#48995)
* REGR: to_parquet raising with bytes filename * Add check * Fix typo * Parametrize
1 parent a97396b commit 56d82a9

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
@@ -189,6 +189,8 @@ def write(
189189
and isinstance(path_or_handle.name, (str, bytes))
190190
):
191191
path_or_handle = path_or_handle.name
192+
if isinstance(path_or_handle, bytes):
193+
path_or_handle = path_or_handle.decode()
192194

193195
try:
194196
if partition_cols is not None:

pandas/tests/io/test_parquet.py

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

0 commit comments

Comments
 (0)