Skip to content

BUG: read_parquet leaks file handles on error #46555

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

Closed
3 tasks done
flying-sheep opened this issue Mar 29, 2022 · 0 comments · Fixed by #46556
Closed
3 tasks done

BUG: read_parquet leaks file handles on error #46555

flying-sheep opened this issue Mar 29, 2022 · 0 comments · Fixed by #46556
Labels
Bug IO Parquet parquet, feather
Milestone

Comments

@flying-sheep
Copy link
Contributor

flying-sheep commented Mar 29, 2022

Pandas version checks

  • I have checked that this issue has not already been reported.
  • I have confirmed this bug exists on the latest version of pandas.
  • I have confirmed this bug exists on the main branch of pandas.

Reproducible Example

Run this in development mode:

from pathlib import Path
import pandas as pd
from pandas.io.parquet import to_parquet, read_parquet

path = Path('/tmp/test.parquet')
to_parquet(pd.DataFrame(dict(a=[1])), path)
with path.open('r+b') as f:
    f.seek(16)
    f.write(b'bogus')

try:
    read_parquet(path)
except Exception:
    pass

Issue Description

The handles aren’t closed in a except/finally block, so they only get closed when everything works.

When running the above in development mode, you’ll see a ResourceWarning

Expected Behavior

all file handles are closed no matter what

Installed Versions

INSTALLED VERSIONS

commit : 06d2301
python : 3.9.12.final.0
python-bits : 64
OS : Linux
OS-release : 5.16.16-zen1-1-zen
Version : #1 ZEN SMP PREEMPT Mon, 21 Mar 2022 22:59:42 +0000
machine : x86_64
processor :
byteorder : little
LC_ALL : None
LANG : de_DE.UTF-8
LOCALE : de_DE.UTF-8
pandas : 1.4.1
numpy : 1.22.3
pytz : 2021.1
dateutil : 2.8.1
pip : 22.0.4
setuptools : 57.4.0
Cython : None
pytest : 7.1.1
hypothesis : None
sphinx : 4.3.2
blosc : None
feather : None
xlsxwriter : 1.4.0
lxml.etree : 4.6.3
html5lib : 1.1
pymysql : None
psycopg2 : 2.8.6
jinja2 : 3.0.3
IPython : 7.23.0
pandas_datareader: None
bs4 : 4.9.3
bottleneck : None
fastparquet : 0.8.0
fsspec : 2022.02.0
gcsfs : None
matplotlib : 3.4.1
numba : 0.53.1
numexpr : 2.7.3
odfpy : None
openpyxl : 3.0.7
pandas_gbq : None
pyarrow : None
pyreadstat : None
pyxlsb : None
s3fs : None
scipy : 1.8.0
sqlalchemy : 1.4.23
tables : 3.6.1
tabulate : 0.8.9
xarray : None
xlrd : 1.2.0
xlwt : None
zstandard : None

@flying-sheep flying-sheep added Bug Needs Triage Issue that has not been reviewed by a pandas team member labels Mar 29, 2022
@twoertwein twoertwein added IO Parquet parquet, feather and removed Needs Triage Issue that has not been reviewed by a pandas team member labels Mar 29, 2022
@jreback jreback added this to the 1.5 milestone Mar 30, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug IO Parquet parquet, feather
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants