Skip to content

Close the workbook in get_xlsx_sheet_info (#1051) - #1055

Merged
yakew7 merged 1 commit into
yakew7:mainfrom
sammist2:fix/1051-close-xlsx-workbook
Oct 18, 2026
Merged

yakew7 merged 1 commit into
yakew7:mainfrom
sammist2:fix/1051-close-xlsx-workbook

Conversation

@sammist2

Copy link
Copy Markdown
Contributor

Fixes #1051.

get_xlsx_sheet_info opened a workbook with pd.ExcelFile(path) only to list its sheet names, but never closed it. The leaked handle raised a ResourceWarning on garbage collection and, on Windows, kept the .xlsx locked against deletion or overwrite.

The sheet names are now read inside a with pd.ExcelFile(path) as book: block, so the workbook is always closed. The existing behavior is unchanged: a non-.xlsx path and an unreadable file still return None.

Added test_get_xlsx_sheet_info_closes_the_workbook in tests/test_loaders.py (it records warnings and forces a collection; fails before the change, passes after) and a CHANGELOG entry under [Unreleased].

get_xlsx_sheet_info opened a workbook with pd.ExcelFile(path) to list
its sheet names but never closed it, leaking the file handle. The
unclosed handle raised a ResourceWarning on garbage collection and, on
Windows, kept the .xlsx locked against deletion or overwrite.

Read the sheet names inside a 'with pd.ExcelFile(path) as book:' block
so the workbook is always closed. Adds a regression test and a
CHANGELOG entry.
@vercel

vercel Bot commented Oct 17, 2026

Copy link
Copy Markdown
Contributor

@sammist2 is attempting to deploy a commit to the yashkewlani2020-gmailcom's projects Team on Vercel.

A member of the Team first needs to authorize it.

@github-actions

Copy link
Copy Markdown

Hey @sammist2, your first PR on Fair Code, that's awesome, thank you.

This project is about making AI more accountable, and contributions like yours are what keep that work going. We'll review your changes shortly.

If you haven't already, give the contributing guide a quick read: it covers how audits are structured and what we look for in a review.

And if you're finding Fair Code useful or interesting, a star on the repo genuinely helps more people find it - no pressure, just appreciated.

@github-actions

Copy link
Copy Markdown

@yakew7 @Shreyash0712 @ahmdkaml - new PR touching a path you own, please review.

@yakew7
yakew7 merged commit 8428af2 into yakew7:main Oct 18, 2026
17 of 18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

get_xlsx_sheet_info leaves the workbook open, which raises a ResourceWarning and keeps the file locked on Windows

2 participants