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.

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

Reproducible Example

import pandas as pd
pd.read_csv('2022_01_k.zip')
# ValueError: Multiple files found in ZIP file. Only one file per ZIP: ['k_d_01_2022.csv', 'k_d_t_01_2022.csv']

Issue Description

Handle to 2022_01_k.zip is left open after failed read attempt (resource leak).

Expected Behavior

Handle to file 2022_01_k.zip is closed. File can be renamed/deleted on Windows.

Installed Versions

INSTALLED VERSIONS ------------------ commit : bdc79c146c2e32f2cab629be240f01658cfb6cc2 python : 3.11.5.final.0 python-bits : 64 OS : Windows OS-release : 10 Version : 10.0.22631 machine : AMD64 processor : Intel64 Family 6 Model 85 Stepping 4, GenuineIntel byteorder : little LC_ALL : None LANG : en LOCALE : Polish_Poland.1250 pandas : 2.2.1 numpy : 1.26.3 pytz : 2023.3.post1 dateutil : 2.8.2 setuptools : 69.2.0 pip : 24.0 Cython : None pytest : None hypothesis : None sphinx : 5.0.2 blosc : None feather : None xlsxwriter : None lxml.etree : 5.1.0 html5lib : 1.1 pymysql : None psycopg2 : None jinja2 : 3.1.3 IPython : 8.20.0 pandas_datareader : None adbc-driver-postgresql: None adbc-driver-sqlite : None bs4 : 4.12.2 bottleneck : None dataframe-api-compat : None fastparquet : None fsspec : None gcsfs : None matplotlib : 3.8.0 numba : None numexpr : 2.8.7 odfpy : None openpyxl : None pandas_gbq : None pyarrow : 15.0.1 pyreadstat : None python-calamine : None pyxlsb : None s3fs : None scipy : None sqlalchemy : None tables : None tabulate : 0.9.0 xarray : None xlrd : None zstandard : 0.19.0 tzdata : 2023.3 qtpy : 2.4.1 pyqt5 : None

Comment From: jsjeon-um

take

Comment From: twoertwein

@jsjeon-um Feel free to ping me if you have questions or when you have a PR!

Comment From: abeltavares

@jsjeon-um are you still working on it? can i take it?

Comment From: tev-dixon

I'll take this.

Comment From: tev-dixon

I was not able to recreate this bug. I tried on both Windows 10/11 and Linux systems with multiple zip files. Looking over the relevant code, I didn't see anything glaringly incorrect. Can anyone else reproduce this?

Comment From: twoertwein

I was not able to recreate this bug. I tried on both Windows 10/11 and Linux systems with multiple zip files. Looking over the relevant code, I didn't see anything glaringly incorrect. Can anyone else reproduce this?

The bug should still exists as we still raise without first cleaning up opened file handlers: https://github.com/pandas-dev/pandas/blob/8a286fa16f3160e939b192cbe8e218992a84e6fc/pandas/io/common.py#L812

You probably need to enable ResoruceWarnings, for example, with python -W default