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

UW-209 #129

Closed
WeirAE opened this issue Dec 12, 2022 · 3 comments
Closed

UW-209 #129

WeirAE opened this issue Dec 12, 2022 · 3 comments
Assignees
Labels
feature Added functionality

Comments

@WeirAE
Copy link
Contributor

WeirAE commented Dec 12, 2022

Description
https://jira-epic.woc.noaa.gov/browse/UW-209

Requirements
Test that the assumptions that the polymorphism built into the Config subclasses for YAML, namelists and INI files is sufficient to transform to another subclass. May require making the input file path optional in the 'init' methods of each.

Acceptance Criteria (Definition of Done)
One additional test in test_config.py must test all transform combinations and complete successfully

@WeirAE
Copy link
Contributor Author

WeirAE commented Jan 3, 2023

Test comparisons are as follows:
INI vs YAML
False
YAML ref: ['salad:', ' base: kale', ' fruit: banana', ' vegetable: tomato', ' how_many: 12', ' dressing: balsamic']
YAML out: ['salad:', ' base: kale', ' fruit: banana', ' vegetable: tomato', " how_many: '12'", ' dressing: balsamic']

INI vs F90
False
F90 ref: ['&salad', " base = 'kale'", " fruit = 'banana'", " vegetable = 'tomato'", ' how_many = 12', " dressing = 'balsamic'", '/']
F90 out: ['&salad', " base = 'kale'", " dressing = 'balsamic'", " fruit = 'banana'", " how_many = '12'", " vegetable = 'tomato'", '/']

YAML vs INI
False
INI ref: ['[salad]', 'base = kale', 'fruit = banana', 'vegetable = tomato', 'how_many = 12', 'dressing = balsamic', '']
INI out: ["salad={'base': 'kale', 'fruit': 'banana', 'vegetable': 'tomato', 'how_many': 12, 'dressing': 'balsamic'}"]

YAML vs F90
False
F90 ref: ['&salad', " base = 'kale'", " fruit = 'banana'", " vegetable = 'tomato'", ' how_many = 12', " dressing = 'balsamic'", '/']
F90 out: ['&salad', " base = 'kale'", " dressing = 'balsamic'", " fruit = 'banana'", ' how_many = 12', " vegetable = 'tomato'", '/']

F90 vs INI
False
INI ref: ['[salad]', 'base = kale', 'fruit = banana', 'vegetable = tomato', 'how_many = 12', 'dressing = balsamic', '']
INI out: ["salad=OrderedDict([('base', 'kale'), ('fruit', 'banana'), ('vegetable', 'tomato'), ('how_many', 12), ('dressing', 'balsamic')])"]

F90 vs YAML
False
YAML ref: ['salad:', ' base: kale', ' fruit: banana', ' vegetable: tomato', ' how_many: 12', ' dressing: balsamic']
YAML out: ['salad: !!python/object/apply:collections.OrderedDict', '- - - base', ' - kale', ' - - fruit', ' - banana', ' - - vegetable', ' - tomato', ' - - how_many', ' - 12', ' - - dressing', ' - balsamic']

The direct conversion reads from the base object correctly, but once it reads from a dictionary object, there are issues with all dump calls. Primarily, its 'detecting' the dictionary as an OrderedDictionary nested within a standard dictionary, but ConfigParser and YAML don't support ordered dictionaries. There is a workaround updated parser called ConfigObj, but it doesn't allow formats outside of standard INI. It would take some extra steps to get the formatting and string stream into it. YAML I haven't found an answer for yet, could be a newer fork that can handle it. The F90 parser just treats it as an unordered dictionary and scrambles the keys.

@christinaholtNOAA
Copy link
Contributor

I think there are 2 main things going on here...

  1. f90nml deals primarily in OrderedDict objects. If we convert those to regular dicts when we read them in, and then back to OrderedDicts when we write the out, it should take care of the ordering and the weird stuff happening in the F90 vs YAML example above.

  2. I also (somewhat contraversally) think we can remove any single quotes when we compare two lines, just knowing that the two formats differ. Fortran does actually want integers to be strings in a namelist, so this could be a caveat if we had a use case to convert namelists to yaml, which would likely be rare, and could be handled if needed.

@WeirAE
Copy link
Contributor Author

WeirAE commented Jan 4, 2023

Solved by #131

@WeirAE WeirAE closed this as completed Jan 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature Added functionality
Projects
None yet
Development

No branches or pull requests

2 participants