Skip to content

Commit

Permalink
Improve missing data output (#384)
Browse files Browse the repository at this point in the history
* Remove index, justify left and remove shortening for required data output

* Rename required data output column to year(s)

* Adjust tests
  • Loading branch information
phackstock authored Sep 13, 2024
1 parent 6a6e7de commit 71ffcab
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 20 deletions.
9 changes: 8 additions & 1 deletion nomenclature/processor/required_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down
32 changes: 14 additions & 18 deletions tests/test_required_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit 71ffcab

Please sign in to comment.