-
Notifications
You must be signed in to change notification settings - Fork 149
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
Allow mapping distinct names for MESSAGE commodity → MACRO sector #719
Conversation
Codecov Report
@@ Coverage Diff @@
## main #719 +/- ##
=====================================
Coverage 94.4% 94.4%
=====================================
Files 43 43
Lines 3448 3434 -14
=====================================
- Hits 3257 3245 -12
+ Misses 191 189 -2
|
Simplifies add_model_data()
- Explode Calculate class to individual functions. - Fix MESSAGE commodity–MACRO sector mapping. - Improve pandas usage, add docstrings, typing. - Remove redundant globals.
- Reflow lines. - Use consistent heading structure. - Add missing reference label. - Expand API documentation
This appears to only be an issue on Python 3.7.
- Add _notna() reference value. - Expand typing. - Remove redundant/trivial methods k0() - Explictly retrieve vars in calibrate()
- Also ignore missing typing in scipy.optimize. - Work around khaeru/genno#54 (Quantity.pipe).
pytest.raises(ValueError, c.read_data) | ||
|
||
c = macro.prepare_computer(westeros_solved, data=data) | ||
with pytest.raises(Exception, match="Missing expected columns.*year"): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The formulation of match
seems odd to me here, so just to make sure: is the raised error message really referencing something like columns.gdp_calibrate.year
? The MissingKeyError in genno seems to be phrased differently, at least.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi, yes. This exception is raised by the function .macro._validate_data()—in full it is something like "Missing expected columns for gdp_calibration: {'year'}"
. pytest.raises(…, match=…) is treated as a regular expression, so the .*
matches a bunch of characters in the middle.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Apart from that one clarifying question, the new tests look good to me, very streamlined.
To build the docs locally, I ran sphinx-build -T -E -d _build/doctrees-readthedocs -D language=en . _build/html as suggested in our own docs. This command produces a few warnings, which might be related to your changes: Cannot locate code for 'message_ix.models.DEFAULT_CPLEX_OPTIONS' or parent class/module
Cannot locate code for 'message_ix.models.MESSAGE_ITEMS' or parent class/module
Cannot locate code for 'message_ix.macro.MACRO_ITEMS' or parent class/module The local docs render slightly differently on e.g. https://docs.messageix.org/en/latest/api.html, where the initial list does not have any bullet points in my local version. The same is true for https://docs.messageix.org/en/latest/macro.html, where the nested structure is also lost for the table-of-content-list. But this does not seem to be specific to this PR because it happens on all other pages as well. Apart from that, the docs-part is looking good to me. |
Yes, that's related to the Sphinx extension |
This functionality is implied to work but, per the added test on the initial commits on this branch, does not. See e.g. here:
This occurs because of code like:
message_ix/message_ix/macro.py
Lines 473 to 475 in 6dee23a
Data originating from MESSAGE's
PRICE_COMMODITY
is sent to MACRO'sprice_MESSAGE
, with thecommodity
dimension renamed tosector
, but the mapping provided by the user in the config data is never applied.This code ultimately dates back to #223, and was not altered in #327. Tests were never added for this functionality.
The PR fixes the bug and makes other improvements:
genno
to structure the functions, as suggested atmessage_ix/message_ix/macro.py
Lines 323 to 324 in cec4092
price_ref
. In this case, as is common in actual use, they are back-extrapolated from data (e.g.PRICE_COMMODITY
) in the scenario which is being calibrated.Housekeeping:
ixmp.utils.sphinx_linkcode_github
; items in the documentation are now linked directly to their source on GitHub.How to review
Scenario.add_macro
; confirm that it continues to work as expected.PR checklist