Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update RequiredDataValidator #281

Merged

Conversation

phackstock
Copy link
Contributor

This PR updates RequiredDataValidator to make use of the pyam update to require_data and now presents the missing data accurately.

Example:

ERROR    nomenclature.processor.required_data:required_data.py:189 Required data from: tests/data/required_data/required_data/requiredData_apply_error.yaml missing: 
WARNING  nomenclature.processor.required_data:required_data.py:193 
                                                  year
model   scenario variable       unit                  
model_a scen_a   Primary Energy GWh/yr  2005,2010,2015
        scen_b   Primary Energy GWh/yr  2005,2010,2015

@phackstock phackstock self-assigned this Sep 4, 2023
@phackstock phackstock force-pushed the fix/update-required-data-validator branch from ac55744 to bb82a48 Compare September 4, 2023 17:05
@danielhuppmann
Copy link
Member

danielhuppmann commented Sep 5, 2023

I think it's confusing to have an error, then a warning - better to combine this into one log item.

Also, you could use the (new) pyam utility format_log_message() (see here) to combine a message and the (head of the) table of missing rows. (Maybe make the number of rows configurable?)

@danielhuppmann
Copy link
Member

Maybe also put the required-file-path somewhere else to make it more readable, like

ERROR    nomenclature.processor.required_data:required_data.py:189 Missing required data.
File: 'tests/data/required_data/required_data/requiredData_apply_error.yaml'
Missing rows:
                                                  year
model   scenario variable       unit                  
model_a scen_a   Primary Energy GWh/yr  2005,2010,2015
        scen_b   Primary Energy GWh/yr  2005,2010,2015

@phackstock
Copy link
Contributor Author

phackstock commented Sep 5, 2023

Good point @danielhuppmann, I've updated the log message, now it looks like this:

ERROR    nomenclature.processor.required_data:required_data.py:161 Missing required data.
File: tests/data/required_data/required_data/requiredData_apply_error.yaml
Missing rows:

   index    model scenario        variable    unit            year
0      0  model_a   scen_a  Primary Energy  GWh/yr  2005,2010,2015
1      1  model_a   scen_a  Primary Energy    Mtoe  2005,2010,2015
2      2  model_a   scen_b  Primary Energy  GWh/yr  2005,2010,2015
3      3  model_a   scen_b  Primary Energy    Mtoe  2005,2010,2015

   index    model scenario      variable
0      0  model_a   scen_a  Final Energy
1      1  model_a   scen_b  Final Energy

   index    model scenario       variable       unit
0      0  model_a   scen_a  Emissions|CO2  Mt CO2/yr
1      1  model_a   scen_b  Emissions|CO2  Mt CO2/yr

   index    model scenario region      variable
0      0  model_a   scen_a  World  Final Energy
1      1  model_a   scen_b  World  Final Energy

a bit more readable I think.

@danielhuppmann
Copy link
Member

If you can remove the index columns, I’ll be 100% happy…

@phackstock
Copy link
Contributor Author

Ah yeah sure, that wasn't supposed to be there, sorry for that.

@phackstock
Copy link
Contributor Author

@danielhuppmann cleaned up the output, should be good now:

ERROR    nomenclature.processor.required_data:required_data.py:161 Missing required data.
File: tests/data/required_data/required_data/requiredData_apply_error.yaml
Missing rows:

     model scenario        variable    unit            year
0  model_a   scen_a  Primary Energy  GWh/yr  2005,2010,2015
1  model_a   scen_a  Primary Energy    Mtoe  2005,2010,2015
2  model_a   scen_b  Primary Energy  GWh/yr  2005,2010,2015
3  model_a   scen_b  Primary Energy    Mtoe  2005,2010,2015

     model scenario      variable
0  model_a   scen_a  Final Energy
1  model_a   scen_b  Final Energy

     model scenario       variable       unit
0  model_a   scen_a  Emissions|CO2  Mt CO2/yr
1  model_a   scen_b  Emissions|CO2  Mt CO2/yr

     model scenario region      variable
0  model_a   scen_a  World  Final Energy
1  model_a   scen_b  World  Final Energy

Copy link
Member

@danielhuppmann danielhuppmann left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One more suggestion - instead of iterating over the models within the missing_data assignment, do the loop outside. Then, you could omit the model column from the tables of missing data and instead have it in the log-error message, like

f"Missing required data for model '{model}'."
This would make a more concise output, in particular when we have very long variable names...

nomenclature/processor/required_data.py Outdated Show resolved Hide resolved
@phackstock
Copy link
Contributor Author

Shortened the output, it's now:

ERROR    nomenclature.processor.required_data:required_data.py:166 Missing required data.
File: tests/data/required_data/required_data/requiredData_apply_error.yaml

Missing for model_a:
  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

@phackstock
Copy link
Contributor Author

Seems like that last update broke some tests, sorry for that, taking a look now.

@phackstock
Copy link
Contributor Author

All good now.

Copy link
Member

@danielhuppmann danielhuppmann left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Final suggestion to use single-quotes around the model name, and maybe deactivate py3.11 tests until we can release pyam 2.0

@phackstock
Copy link
Contributor Author

Done

Copy link
Member

@danielhuppmann danielhuppmann left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@phackstock phackstock merged commit 3117673 into IAMconsortium:main Sep 6, 2023
5 checks passed
@phackstock phackstock deleted the fix/update-required-data-validator branch September 6, 2023 10:52
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.

2 participants