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 a function to retrieve years in which a series crosses a threshold #101

Merged
merged 6 commits into from Oct 5, 2018

Conversation

danielhuppmann
Copy link
Member

@danielhuppmann danielhuppmann commented Oct 1, 2018

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

This PR adds a pyam.cross_threshold() function to retrieve a list of years in which a pd.Series (e.g., a timeseries row) crosses a given threshold.

@gidden
Copy link
Member

gidden commented Oct 4, 2018

this looks good @danielhuppmann, but it's a little confusing because the crossing could be in the positive (below to above) or negative (above to below). I think that information should be included in what is returned.

Also, maybe add a test for one that does not cross a threshold?

@danielhuppmann
Copy link
Member Author

thanks @gidden!

Added a test where cross_threshold() returns an empty list (because not crossing the threshold).

On returning the direction of crossing, not sure what would be suitable return format - any ideas? Alternatively, the function could take an additional optional from=['above', 'below'] kwarg that filters the returned list.

@gidden
Copy link
Member

gidden commented Oct 4, 2018

Yes, I would add a kwarg like direction.

@danielhuppmann
Copy link
Member Author

I was thinking of direction at first, too, but how would you then name the options? direction=up is ambiguous. That's why I thought from would be more intuitive...


def test_cross_treshold_direction_error():
y = pd.Series(data=[np.nan, 1, 3, 1], index=[2002, 2005, 2007, 2013])
pytest.raises(ValueError, cross_threshold, x = y, threshold=2,

Choose a reason for hiding this comment

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

E251 unexpected spaces around keyword / parameter equals

def test_cross_treshold_direction_error():
y = pd.Series(data=[np.nan, 1, 3, 1], index=[2002, 2005, 2007, 2013])
pytest.raises(ValueError, cross_threshold, x = y, threshold=2,
direction='up')

Choose a reason for hiding this comment

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

W292 no newline at end of file

@danielhuppmann
Copy link
Member Author

@gidden, added a kwarg direction=['from above', 'from below'] and three more tests for that feature...

Should be good to go once the tests pass

@gidden
Copy link
Member

gidden commented Oct 5, 2018

perfect, thanks!

@gidden gidden merged commit 4bd83dd into IAMconsortium:master Oct 5, 2018
@danielhuppmann danielhuppmann deleted the cross_threshold branch October 5, 2018 07:58
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.

None yet

3 participants