Pandas version checks

  • [X] I have checked that this issue has not already been reported.

  • [X] I have confirmed this bug exists on the latest version of pandas.

  • [x] I have confirmed this bug exists on the main branch of pandas.

Reproducible Example


import io

from pandas import read_parquet

df = read_parquet("./i_am_file.parquet")

byteio = io.BytesIO()  # engine=auto|fastparuet
df.to_parquet(byteio, engine="fastparquet")
byteio.seek(0)  # ValueError: I/O operation on closed file.
print(byteio.getvalue())


# there is no error in to_csv() 
df = read_csv("./test_result.csv")

byteio = io.BytesIO()  
df.to_csv(byteio)
byteio.seek(0)
print(byteio.getvalue())

# pandas==1.5.3 & fastparquet==2023.4.0~2022.11.0
Traceback (most recent call last):
  File ".../i_am_example.py", line 7, in <module>
    bb = io.BytesIO(df.to_parquet())
  File "../virtualenvs/i_am_project-7z3L305f-py3.10/lib/python3.10/site-packages/pandas/util/_decorators.py", line 211, in wrapper
    return func(*args, **kwargs)
  File ".../virtualenvs/i_am_project-7z3L305f-py3.10/lib/python3.10/site-packages/pandas/core/frame.py", line 2976, in to_parquet
    return to_parquet(
  File ".../virtualenvs/i_am_project-7z3L305f-py3.10/lib/python3.10/site-packages/pandas/io/parquet.py", line 442, in to_parquet
    return path_or_buf.getvalue()
ValueError: I/O operation on closed file.


# pandas==2.0.1 & fastparquet==2023.4.0~2022.11.0
Traceback (most recent call last):
  File ".../i_am_example.py", line 9, in <module>
    byteio.seek(0)  # ValueError: I/O operation on closed file.
ValueError: I/O operation on closed file.

Issue Description

hi i'm not sure where to ask about this, but I'd like to start by asking here

Expected Behavior

no raise ValueError: I/O operation on closed file.

Installed Versions

pandas==1.5.3 & fastparquet==2023.4.0~2022.11.0

pandas==2.0.1 & fastparquet==2023.4.0~2022.11.0

Comment From: phofl

Hi, thanks for your report. Duplicate of #51140