From 71ffcabe92e3ff8224d0e4407fac73406d523983 Mon Sep 17 00:00:00 2001 From: Philip Hackstock <20710924+phackstock@users.noreply.github.com> Date: Fri, 13 Sep 2024 10:05:23 +0200 Subject: [PATCH] Improve missing data output (#384) * Remove index, justify left and remove shortening for required data output * Rename required data output column to year(s) * Adjust tests --- nomenclature/processor/required_data.py | 9 +++++- .../requiredData_apply_error.yaml | 2 +- tests/test_required_data.py | 32 ++++++++----------- 3 files changed, 23 insertions(+), 20 deletions(-) diff --git a/nomenclature/processor/required_data.py b/nomenclature/processor/required_data.py index 3d229e81..65643bd9 100644 --- a/nomenclature/processor/required_data.py +++ b/nomenclature/processor/required_data.py @@ -178,7 +178,13 @@ def apply(self, df: IamDataFrame) -> IamDataFrame: for model, data_list in missing_data.items(): missing_data_log_info += f"Missing for '{model}':\n" for data in data_list: - missing_data_log_info += f"{data}\n\n" + missing_data_log_info += ( + data.to_string( + index=False, + justify="left", + ) + + "\n\n" + ) logger.error( "Missing required data.\nFile: %s\n\n%s", get_relative_path(self.file), @@ -212,6 +218,7 @@ def check_required_data_per_model( .to_frame() .reset_index() .drop(columns=["model"]) + .rename(columns={"year": "year(s)"}) ) return missing_data diff --git a/tests/data/required_data/required_data/requiredData_apply_error.yaml b/tests/data/required_data/required_data/requiredData_apply_error.yaml index d309ddfb..b52dd085 100644 --- a/tests/data/required_data/required_data/requiredData_apply_error.yaml +++ b/tests/data/required_data/required_data/requiredData_apply_error.yaml @@ -1,7 +1,7 @@ model: model_a required_data: - measurand: - - Primary Energy: + - Primary Energy|Making sure that a really long variable is displayed completely: unit: [GWh/yr, Mtoe] year: [2005, 2010, 2015] # 2015 is missing from simple_df for all models - variable: Final Energy diff --git a/tests/test_required_data.py b/tests/test_required_data.py index e616e250..cbb90741 100644 --- a/tests/test_required_data.py +++ b/tests/test_required_data.py @@ -100,24 +100,20 @@ def test_RequiredData_apply_raises(simple_df, caplog): required_data_validator.apply(simple_df) missing_data = [ - """ - scenario variable unit year -0 scen_a Primary Energy GWh/yr 2005,2010,2015 -1 scen_a Primary Energy Mtoe 2005,2010,2015 -2 scen_b Primary Energy GWh/yr 2005,2010,2015 -3 scen_b Primary Energy Mtoe 2005,2010,2015""", - """ - scenario variable -0 scen_a Final Energy -1 scen_b Final Energy""", - """ - scenario variable unit -0 scen_a Emissions|CO2 Mt CO2/yr -1 scen_b Emissions|CO2 Mt CO2/yr""", - """ - scenario region variable -0 scen_a World Final Energy -1 scen_b World Final Energy""", + """scenario variable unit year(s)""", + """scen_a Primary Energy|Making sure that a really long variable is displayed completely GWh/yr 2005,2010,2015 +scen_a Primary Energy|Making sure that a really long variable is displayed completely Mtoe 2005,2010,2015 +scen_b Primary Energy|Making sure that a really long variable is displayed completely GWh/yr 2005,2010,2015 +scen_b Primary Energy|Making sure that a really long variable is displayed completely Mtoe 2005,2010,2015""", + """scenario variable""", + """scen_a Final Energy +scen_b Final Energy""", + """scenario variable unit""", + """scen_a Emissions|CO2 Mt CO2/yr +scen_b Emissions|CO2 Mt CO2/yr""", + """scenario region variable""", + """scen_a World Final Energy +scen_b World Final Energy""", ] # check if the log message contains the correct information assert all(