From 5d5f4503007dc6d9f1545fdf026787e2f922cf0d Mon Sep 17 00:00:00 2001 From: Matt Graham Date: Mon, 13 Nov 2023 11:36:19 +0000 Subject: [PATCH] Locally disable pylint E0110 as false positive Also refactor to use ExcelWriter as context manager as recommended in docs --- pyproject.toml | 1 - src/tlo/analysis/utils.py | 20 +++++++++----------- 2 files changed, 9 insertions(+), 12 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 2d08c48ba0..1b7062054e 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -93,7 +93,6 @@ disable = [ "R", "C", "W", - "E0110", # abstract class instantiated "E0611", # no-name-in-module "E0702", # raising NoneType "E1136", # unsubscriptable type diff --git a/src/tlo/analysis/utils.py b/src/tlo/analysis/utils.py index 2ec34c7b82..f22cb7d70a 100644 --- a/src/tlo/analysis/utils.py +++ b/src/tlo/analysis/utils.py @@ -96,17 +96,15 @@ def write_log_to_excel(filename, log_dataframes): sheet_count += 1 metadata.append([module, key, sheet_count, dataframes['_metadata'][module][key]['description']]) - writer = pd.ExcelWriter(filename) - index = pd.DataFrame(data=metadata, columns=['module', 'key', 'sheet', 'description']) - index.to_excel(writer, sheet_name='Index') - - sheet_count = 0 - for module, dataframes in log_dataframes.items(): - for key, df in dataframes.items(): - if key != '_metadata': - sheet_count += 1 - df.to_excel(writer, sheet_name=f'Sheet {sheet_count}') - writer.save() + with pd.ExcelWriter(filename) as writer: # https://github.com/PyCQA/pylint/issues/3060 pylint: disable=E0110 + index = pd.DataFrame(data=metadata, columns=['module', 'key', 'sheet', 'description']) + index.to_excel(writer, sheet_name='Index') + sheet_count = 0 + for module, dataframes in log_dataframes.items(): + for key, df in dataframes.items(): + if key != '_metadata': + sheet_count += 1 + df.to_excel(writer, sheet_name=f'Sheet {sheet_count}') def make_calendar_period_lookup():