Skip to content

Commit

Permalink
Exclude Namelist in __setitem__ list of dicts
Browse files Browse the repository at this point in the history
Previously, if given a list of dicts or Namelists, we could explictly
convert every (non-None) element into a Namelist, even if it was already
a namelist.  This is both redundant and recursive, since it would
subsequently apply this to any potential Namelist records within the
Namelist.

We now exlude Namelists from this conversion, under the assumption that
they would have been handled during the original conversion to Namelist.

This has improved the performance of namelists using lists of derived
types.  Thanks for Jacob Williams for reporting.
  • Loading branch information
marshallward committed Jul 17, 2019
1 parent 73eadd2 commit 907aa4c
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions f90nml/namelist.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,13 +118,14 @@ def __setitem__(self, key, value):

elif is_nullable_list(value, dict):
for i, v in enumerate(value):
if v is not None:
if isinstance(v, Namelist) or v is None:
value[i] = v
else:
# value is a non-Namelist dict
value[i] = Namelist(
v,
default_start_index=self.default_start_index
)
else:
value[i] = None

super(Namelist, self).__setitem__(key.lower(), value)

Expand Down

0 comments on commit 907aa4c

Please sign in to comment.