-
Notifications
You must be signed in to change notification settings - Fork 221
Raise an error if no value can be found for a namelist variable #3988
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
Changes from all commits
3f3396e
4ccd2a3
cb55d7b
e0e5535
3c1840c
747fcd8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -156,6 +156,10 @@ def get_group(self, name): | |
| def add_attributes(self, attributes): | ||
| self._attributes = attributes | ||
|
|
||
| def get_attributes(self): | ||
| """Return this object's attributes dictionary""" | ||
| return self._attributes | ||
|
|
||
| def get_entry_nodes(self): | ||
| return self._entry_nodes | ||
|
|
||
|
|
@@ -174,6 +178,9 @@ def set_value(self, vid, value, subgroup=None, ignore_type=True): | |
| """This function is not implemented.""" | ||
| raise TypeError("NamelistDefinition does not support `set_value`.") | ||
|
|
||
| # In contrast to the entry_id version of this method, this version doesn't support the | ||
| # replacement_for_none argument, because it is hard-coded to ''. | ||
| # pylint: disable=arguments-differ | ||
| def get_value_match(self, vid, attributes=None, exact_match=True, entry_node=None): | ||
| """Return the default value for the variable named `vid`. | ||
|
|
||
|
|
@@ -190,11 +197,12 @@ def get_value_match(self, vid, attributes=None, exact_match=True, entry_node=Non | |
|
|
||
| if entry_node is None: | ||
| entry_node = self._nodes[vid] | ||
| # NOTE(wjs, 2021-06-04) In the following call, replacement_for_none='' may not | ||
| # actually be needed, but I'm setting it to maintain some old logic, to be safe. | ||
| value = super(NamelistDefinition, self).get_value_match(vid.lower(),attributes=all_attributes, exact_match=exact_match, | ||
| entry_node=entry_node) | ||
| if value is None: | ||
| value = '' | ||
| else: | ||
| entry_node=entry_node, | ||
| replacement_for_none='') | ||
| if value is not None: | ||
| value = self._split_defaults_text(value) | ||
|
|
||
| return value | ||
|
|
@@ -445,4 +453,4 @@ def get_default_value(self, item, attribute=None): | |
| all_attributes.update(attribute) | ||
|
|
||
| value = self.get_value_match(item.lower(), all_attributes, True) | ||
| return self._split_defaults_text(value) | ||
| return value | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The original motivation for this change was seeing that |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -172,6 +172,7 @@ | |
| <value component="glc">$GLC_PIO_NETCDF_FORMAT</value> | ||
| <value component="wav">$WAV_PIO_NETCDF_FORMAT</value> | ||
| <value component="iac">$IAC_PIO_NETCDF_FORMAT</value> | ||
| <value component="esp">$ESP_PIO_NETCDF_FORMAT</value> | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure if this is the right setting: other esp pio values seem to be set to some "undefined" value. But this seemed more right than the earlier behavior, where this was left as blank in the namelist file. |
||
| </values> | ||
| </entry> | ||
|
|
||
|
|
||
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.
As I say in the comment, I don't know if this replacement_for_none is actually needed; I added it to be safe to maintain existing logic. @jedwards4b @jgfouca do you know off-hand if a None value can be generated from the text value retrieved by entry_id's get_value_match? If you'd like, I can do some testing of whether this is ever triggered in CESM testing and remove it if it isn't.
Also: I don't love that the interface of get_value_match now differs from the entry_id version (requiring
#pylint: disable=arguments-differ), but this seemed better to me than other implementations I could think of. I'm open to suggestions if you see a better way to do this.