Skip to content

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. #41778

Closed
@SAH-UJA

Description

@SAH-UJA

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugIO Excelread_excel, to_excelRegressionFunctionality that used to work in a prior pandas version

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions