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

Add to_ixmp4() method #797

Merged
merged 22 commits into from
Feb 22, 2024
Merged

Conversation

danielhuppmann
Copy link
Member

@danielhuppmann danielhuppmann commented Nov 3, 2023

Please confirm that this PR has done the following:

  • Tests Added
  • Documentation Added
  • Name of contributors Added to AUTHORS.rst
  • Description in RELEASE_NOTES.md Added

Description of PR

This PR adds a method to_ixmp4() to easily save all scenarios in an IamDataFrame (including meta indicators) to an ixmp4 platform database instance.

The method name to_ixmp4() doesn't seem elegant, any alternative suggestions of comments?

Copy link

codecov bot commented Nov 3, 2023

Codecov Report

Attention: 1 lines in your changes are missing coverage. Please review.

Comparison is base (98cb3ed) 94.6% compared to head (0da2f88) 94.8%.
Report is 1 commits behind head on main.

Files Patch % Lines
pyam/ixmp4.py 94.4% 1 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##            main    #797     +/-   ##
=======================================
+ Coverage   94.6%   94.8%   +0.1%     
=======================================
  Files         62      64      +2     
  Lines       6040    6089     +49     
=======================================
+ Hits        5719    5775     +56     
+ Misses       321     314      -7     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Contributor

@phackstock phackstock left a comment

Choose a reason for hiding this comment

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

Looks good to me.
Just one potential issues that I'd see.
What if an error occurs between lines 2347 and 2351?
This way we could end up in a situation where a run is created and no data are added.
Or data are added but the run isn't set as default.
@meksor is more qualified to speak on this but I wonder if it's possible to wrap this entire operation in a try...except clause and roll back the changes in the data base in case anything goes wrong.

@danielhuppmann
Copy link
Member Author

Nice catch, @phackstock. A roll-back is not possible in ixmp4 (because the creation of a run and adding of a run are separate actions), and there is no possibility (yet) to delete a run., but I'll add a to-do.

@phackstock
Copy link
Contributor

Ah I see, then the quick fix might be to still use a try except and delete the whole run if we encounter an error. Just to avoid having half finished ghost runs.

@danielhuppmann danielhuppmann marked this pull request as ready for review November 15, 2023 10:09
@danielhuppmann
Copy link
Member Author

danielhuppmann commented Nov 15, 2023

Added an issue to delete runs in ixmp4, see iiasa/ixmp4#29.

Added a quickfix and tests to at least test for the obvious failures...

Once this PR is merged, I'll add a method read_ixmp4().

Copy link
Contributor

@phackstock phackstock left a comment

Choose a reason for hiding this comment

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

Looks good to me in principle.
Some minor comments and questions in line.

pyam/ixmp4.py Outdated