BUG: Pandas doesn't release the lock when a corrupted file is fed in. pandas==1.2.1 worked fine but pandas==1.2.4 has this issue. · Issue #41778 · pandas-dev/pandas (original) (raw)
Kindly refer the following code snippet.
import pandas as pd
import os
# Creating a corrupted file
with open('a.xlsx', 'w') as f:
pass
# Reading using pd.ExcelFile
data = pd.ExcelFile('a.xlsx', engine='openpyxl')
# Deleting the file
os.remove('a.xlsx')
Here, I create a .xlsx file which is not the correct way to make xlsx file but this will express my concern. Then I use pd.ExcelFile to read the xlsx file but it gives me zipfile.BadZipFile: File is not a zip file
which is fine but later when I try to delete that file I get PermissionError: [WinError 32] The process cannot access the file because it is being used by another process: 'a.xlsx'
. This doesn't happen in pandas==1.2.1
and lower version. The current version i.e. pandas==1.2.4
has this bug.