IAMconsortium / pyam

Analysis & visualization of energy & climate scenarios
https://pyam-iamc.readthedocs.io/
Apache License 2.0
220 stars 115 forks source link

Pyam read Excel does not close file #817

Closed phackstock closed 4 months ago

phackstock commented 4 months ago

While working together with @adrivinca we discovered a bug in how pyam reads Excel files. In https://github.com/IAMconsortium/pyam/blob/0762055f318c9adf8df0275e8c11de3544419bdd/pyam/utils.py#L102-L130

a pd.ExcelFile instance is created but never closed. This means that during runtime, Excel files that were opened to read cannot be deleted since they're never closed. When using a temporary directory that is cleaned up at some point, this causes an error on Windows systems since the file will still be open.

Closing the file properly might also significantly decrease pyam's memory hunger when reading Excel files.