Skip to content

Commit

Permalink
[ctml2yaml] Fix integer-like reaction IDs error
Browse files Browse the repository at this point in the history
reaction_id nodes that look like integers (e.g., '0001') are being read
as integers by the parser and converting them to strings throws errors.
The fix is to only include the reaction_id if it doesn't look like an
integer.
  • Loading branch information
bryanwweber committed Aug 23, 2019
1 parent 037dae9 commit bcf03a3
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion interfaces/cython/cantera/ctml2yaml.py
Original file line number Diff line number Diff line change
Expand Up @@ -526,7 +526,13 @@ def convert(inpfile, outfile):
reaction_attribs = {}
reaction_id = reaction.get("id", False)
if reaction_id:
reaction_attribs["id"] = reaction_id
# If the reaction_id can be converted to an integer, it was likely
# added automatically, so there's no need to include it in the
# output.
try:
reaction_id = int(reaction_id)
except ValueError:
reaction_attribs["id"] = reaction_id
reaction_type = reaction.get("type")
rate_coeff = reaction.find("rateCoeff")
if reaction_type in [None, "threeBody", "plog", "chebyshev", "surface", "edge"]:
Expand Down

0 comments on commit bcf03a3

Please sign in to comment.