-
Notifications
You must be signed in to change notification settings - Fork 14
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
MetaCode and MetaCodeList classes with allowed_values attribute #246
MetaCode and MetaCodeList classes with allowed_values attribute #246
Conversation
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.
Thanks @GretchenSchowalter, a few suggestions inline...
nomenclature/codelist.py
Outdated
validation_schema: ClassVar[str] = "meta indicators" | ||
|
||
@classmethod | ||
def from_yaml_files(cls, name: str, path: Path, file_glob_pattern: str = "**/*"): |
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.
Why not keep the from_directory()
convention here? I think we should keep the meta-indicators in a "meta" folder for consistency.
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.
I second that one it should definitely be called from_directory()
otherwise DataStructureDefinition
cannot use it.
Probably should implement a MetaCodeList
class that enforces that ...
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.
Looking at this again, I don't think the method is actually needed at all. Since MetaCodeList
inherits from CodeList
and CodeList
implements from_directory
we should be good.
tests/test_code.py
Outdated
|
||
|
||
def test_MetaCode_allowed_values_attribute(): | ||
reg = MetaCode( |
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.
reg = MetaCode( | |
meta = MetaCode( |
""" | ||
# TODO write all dimensions to the file | ||
self.variable.to_excel(excel_writer, sheet_name, sort_by_code, **kwargs) | ||
import logging |
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.
Not sure why GitHub thinks this entire file was changed?
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.
I was wondering the same, might even be a GitHub issue.
nomenclature/definition.py
Outdated
from nomenclature.validation import validate | ||
|
||
logger = logging.getLogger(__name__) | ||
SPECIAL_CODELIST = {"variable": VariableCodeList, "region": RegionCodeList} |
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.
Please add the MetaCodeList here.
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.
Thanks @GretchenSchowalter for starting this work on the MetaCodes.
Also a few suggestions from my side.
Hello! Thanks for all your feedback. I decided to try getting rid of the method I created in the MetaCodeList class and just use the from_directory() from the CodeList class, but to do so I had to make a few adjustments. For example, making sure that from_directory() creates a list of MetaCodes, rather than a list of Codes. I also had to create a meta_schema.yaml file for the validate() to work within the from_directory() method. |
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.
Sorry for the schema confusion.
@danielhuppmann please correct me if you're of a different opinion but I'd vote to remove all the schemas anyway soon. @GretchenSchowalter for some context, this was an early attempt at defining the file structures for codelists. The idea is that the yaml file is validated against the schema before it is even parsed into the codes.
In reality this never added that much value since a faulty code list would just fail at a different point and the information given by the validation schema was not any better than the one from pydantic.
I'd vote to remote the schema from this PR, after that it's good to be merged from my side.
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.
Good to be merged, from my side, thanks @GretchenSchowalter. 👍.
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.
Nice work, thanks!
Hello! This is my first attempt at addressing issue #241. I have added MetaCode and MetaCodeList classes, where MetaCode has the attribute allowed_values. Within the MetaCodeList class, there is a method from_yaml_files() (which is very similar to the from_directory() method in RegionCodeList) which reads the .yaml files and creates a MetaCodeList. I've also added two very simple tests. I wasn't really sure how to guarantee that the from_yaml_files() method read from a folder called meta, so I would be grateful for a suggestion!