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

Hierarchy Filter (first pull request) #226

Merged
merged 23 commits into from
Mar 15, 2023

Conversation

GretchenSchowalter
Copy link
Contributor

I've added the hierarchy filter to the codelist.py file, and two different tests to the test_codelist.py.

Short explanation: The filter requires two arguments: self and the particular hierarchy you want to filter for. The first step in the function is the creation of an empty list called countries. Then iterating through the values of the self.mapping.values(), we then can compare if the hierarchy for each region matches the hierarchy argument. If so, then the name of that country is appended to the countries[] list. Once the computer has iterated through self.mapping.values(), it then checks if the countries[] list is empty. If not, then filter has worked and it returns the list of names. If the countries[] list is still empty, then either the hierarchy argument inputted is not used for the particular model, or the hierarchy argument has a typo.

I have just a couple questions:

  1. Right now the hierarchy_filter(hierarchy: str) returns a List[str] with just the names of each of the regions that compose that particular hierarchy. Would it be better if the filter instead returned List[Code]?

  2. Would it be helpful to add another level of filtration? For example, print(hierarchy_filter(R5)) prints OECD & EU, Asia, Reforming economies, Latin America, Middle East, and Other. Then one step further, print(hierarchy_filter(OECD & EU)) prints Australia, Austria, Belgium,..., United States.

@phackstock phackstock requested review from danielhuppmann and phackstock and removed request for danielhuppmann March 1, 2023 10:12
@danielhuppmann
Copy link
Member

Thanks for the initial PR, @GretchenSchowalter! To directly answer your first question, I think that ideally, the filter-option should return a RegionCodeList instance (downselected to the relevant items). This way, a user can easily "chain" multiple operations.

The hierarchy filter now returns an instance of the RegionCodeList
@GretchenSchowalter
Copy link
Contributor Author

Okay! Thanks for the feedback! I've updated the code, so I will make another pull request soon.

@danielhuppmann
Copy link
Member

No need to close the PR and start a new one, @GretchenSchowalter - simply add new commits to this branch…

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.

Two additional minor comments...

nomenclature/codelist.py Outdated Show resolved Hide resolved
nomenclature/codelist.py Outdated Show resolved Hide resolved
GretchenSchowalter and others added 5 commits March 6, 2023 09:37
Fixing errors with Stickler
Co-authored-by: Daniel Huppmann <dh@dergelbesalon.at>
changing name from "hierarchy_filter" to "filter"

Co-authored-by: Daniel Huppmann <dh@dergelbesalon.at>
changed the "hierarchy_filter()" to just "filter()"
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 quite good to me, nice work @GretchenSchowalter.
Just two minor comments below.

nomenclature/codelist.py Outdated Show resolved Hide resolved
nomenclature/codelist.py Outdated Show resolved Hide resolved
nomenclature/codelist.py Outdated Show resolved Hide resolved
tests/test_codelist.py Outdated Show resolved Hide resolved
GretchenSchowalter and others added 3 commits March 6, 2023 13:12
Co-authored-by: Philip Hackstock <20710924+phackstock@users.noreply.github.com>
Co-authored-by: Philip Hackstock <20710924+phackstock@users.noreply.github.com>
GretchenSchowalter and others added 5 commits March 6, 2023 14:40
adding list of available filter hierarchy options to the value error, and changing the name of the new RegionCodeList instance to self.name (name of the original RegionCodeList getting filtered).
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, thanks @GretchenSchowalter.
The one open question is if we should add this new feature formally to the docs or if this is more of an internal one anyway. @danielhuppmann, what are your feelings on that?

@danielhuppmann
Copy link
Member

If I see it correctly, the RegionCodeList class is not yet part of the API docs, like https://github.com/IAMconsortium/nomenclature/blob/main/doc/source/api/codelist.rst

It would be sufficient to add it there, I think..

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 for moving forward, @GretchenSchowalter - a few more suggestions inline.

nomenclature/codelist.py Show resolved Hide resolved
nomenclature/codelist.py Show resolved Hide resolved
nomenclature/codelist.py Show resolved Hide resolved
nomenclature/codelist.py Outdated Show resolved Hide resolved
nomenclature/codelist.py Show resolved Hide resolved
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.

Looks good to me! Thanks @GretchenSchowalter, and congrats for your first successful PR!

@phackstock phackstock merged commit 8387291 into IAMconsortium:main Mar 15, 2023
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