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

Default-attributes are exported to yaml #231

Closed
danielhuppmann opened this issue Mar 16, 2023 · 2 comments · Fixed by #247
Closed

Default-attributes are exported to yaml #231

danielhuppmann opened this issue Mar 16, 2023 · 2 comments · Fixed by #247
Assignees

Comments

@danielhuppmann
Copy link
Member

When initializing a VariableCode, the attributes region-aggregation and skip-region-aggregation are automatically added and set to "False". When then exporting the CodeList to yaml, these attributes are written explicitly to the file, leading to very cumbersome, unwieldy files, see for example iiasa/ariadne-intern-workflow#42

This is implemented in this line (and following)

region_aggregation: Optional[List[Dict[str, Dict]]] = Field(

I see two options:

  1. don't automatically add these fields to the VariableCode if they are not defined in the source yaml/xlsx file
  2. remove these attributes (if False) when exporting to yaml
@phackstock
Copy link
Contributor

phackstock commented Mar 20, 2023

Thanks for opening this issue @danielhuppmann.
I have been aware of it and would strongly suggest option 2.
Reason being that it's easier and more logical to work with the values actually set to true or false. I think using none could be ambiguous.
The reason why I didn't fix it in the past was that I didn't find a quick way to check with pydantic if the value that a field has is the default value. But I'm sure there's a way.

@phackstock
Copy link
Contributor

Took a quick look at the pydantic docs (https://docs.pydantic.dev/usage/models/#model-properties) and found a solution in form of the __fields_set__ attribute. It does everything we need.

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 a pull request may close this issue.

3 participants