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

Improve YAML serialization. #193

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

austinlg96
Copy link

For #150.

Creates a custom_yaml object that has alternative "representers" registered to it to modify the default output structures.

Summary:

  • tuple is treated as a list
  • set is treated as a list, but is sorted to ensure that they're serialized in a deterministic way.
  • PurePath and subclasses are stringified
  • ReportType, ScheduleType, and SimTime have yaml_representer static methods and are registered to the custom_yaml object in the custom_yaml.py file.
  • A generic representer is registered on object and its subclasses to catch anything else that is passed in. It creates a WARNING-level log entry to prompt the user that an "implicit" serialization was performed.
  • ReportType had __lt__ defined so that a set[ReportType] could be deterministically serialized, as mentioned above.

Some mediocre testing was included.

NOTE: I believe that import yaml and from nrel...custom_yaml import custom_yaml as yaml both import the same object, so it's not clear to me if the unmodified yaml package would be available. The "package-local" import was still used to make it clear that it is modified.

@austinlg96
Copy link
Author

The output .yml can not be directly imported because the code currently expects an input key, but the output includes an input_config key.

@nreinicke advised that outputing an input key rather than input_config was acceptable. I can try to investigate this change and include it in this PR.

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.

1 participant