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

Removed equiv before performing unit conversion #386

Merged
merged 12 commits into from
Jun 1, 2020

Conversation

Rlamboll
Copy link
Collaborator

@Rlamboll Rlamboll commented May 28, 2020

Please confirm that this PR has done the following:

  • Tests Added
  • Documentation Added
  • Description in RELEASE_NOTES.md Added

Adding to RELEASE_NOTES.md (remove section after adding to RELEASE_NOTES.md)

Please add a single line in the release notes similar to the following:

- (#XX)[http://link-to-pr.com] Added feature which does something

Description of PR

Please describe the changes introduced by this PR.

pyam/units.py Outdated
@@ -75,6 +79,14 @@ def __str__(self):
"\nGWP conversion with IamDataFrame.convert_unit() requires a "
"'gwp_...' *context* and mass-based *to* units.")

def _remove_equivs(string_to_fix):

Choose a reason for hiding this comment

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

E302 expected 2 blank lines, found 1

current = "Mt CO2-equiv/yr"
new = "Mt CH4/yr"
test_df["unit"] = current
converted = test_df.convert_unit(current=current, to=new, context="gwp_AR5GWP100")

Choose a reason for hiding this comment

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

E501 line too long (86 > 79 characters)

@coveralls
Copy link

coveralls commented May 28, 2020

Coverage Status

Coverage decreased (-0.2%) to 86.142% when pulling cc47229 on Rlamboll:co2-equiv into ef2f69a on IAMconsortium:master.

@Rlamboll Rlamboll requested a review from danielhuppmann May 28, 2020 15:44
@Rlamboll
Copy link
Collaborator Author

Seems to have failed a test for time reasons, I don't think I can restart it though

@danielhuppmann
Copy link
Member

Yes, there is some version-conflict in the py3.6 dependencies - guess we'll need to remove that test at some point...

@@ -26,21 +26,24 @@ def convert_unit(df, current, to, factor=None, registry=None, context=None,
# Convert using a pint.UnitRegistry; default the one from iam_units
registry = registry or iam_units.registry

# Make versions without -equiv
Copy link
Member

Choose a reason for hiding this comment

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

I think that having an own function for this simple removal is a bit excessive, you could do that in one line with

current, _to = [i.replace('-equiv', 'e') for i in [current, to]]

(note the _to as an alternative to kee p to for the renaming)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

By leaving out the 'e' this works for all units, even ones without the alias set up.

@@ -46,6 +47,22 @@ def test_convert_unit_with_pint(test_df, current, to):
assert_converted_units(df, current, to, exp)


def test_convert_eqiv_units(test_df):
Copy link
Member

Choose a reason for hiding this comment

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

Should be enough to just add a line to the parametrisation of test_convert_gwp()?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Can do, but I don't really trust this as about a quarter of these tests are broken on my machine, I don't understand why.

Copy link
Member

Choose a reason for hiding this comment

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

did you install the latest version of iam_units from GitHub?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

nope, turns out it had moved on

@@ -1,3 +1,4 @@
import numpy as np

Choose a reason for hiding this comment

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

F401 'numpy as np' imported but unused

@danielhuppmann
Copy link
Member

thanks @Rlamboll, looks great - can you still pull my suggested changes in Rlamboll#2 (or do you disagree?), then good to go!

@Rlamboll
Copy link
Collaborator Author

Honestly I find those variable names very confusing because unless you read that specific line of code, you'd have no idea what those variables were and I would likely assume current was still the input value if I wanted to use it later.

@danielhuppmann
Copy link
Member

Honestly I find those variable names very confusing because unless you read that specific line of code, you'd have no idea what those variables were and I would likely assume current was still the input value if I wanted to use it later.

I pushed another commit to the PR-branch so that the "cleaned" (without -equiv) unit-args are both saved as new internal variables. But I think that cleaning current to _current is much more python than clean_current...

Still, if you can't be convinced, please cherry-pick the other commits (removed unused utility function and add extra test).

@Rlamboll
Copy link
Collaborator Author

Well, you're the one doing the upkeep so if you want those names you can have them.

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 @Rlamboll for this nice addition!

@danielhuppmann danielhuppmann merged commit 2101cfe into IAMconsortium:master Jun 1, 2020
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.

4 participants