Skip to content

Commit

Permalink
Merge 39b5963 into b1baf94
Browse files Browse the repository at this point in the history
  • Loading branch information
richardotis committed Nov 12, 2017
2 parents b1baf94 + 39b5963 commit 0eac6ea
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
3 changes: 2 additions & 1 deletion pycalphad/io/tdb.py
Expand Up @@ -180,7 +180,8 @@ def _tdb_grammar(): #pylint: disable=R0914
int_number = Word(nums).setParseAction(lambda t: [int(t[0])])
pos_neg_int_number = Word('+-'+nums).setParseAction(lambda t: [int(t[0])]) # '+3' or '-2' are examples
# matching float w/ regex is ugly but is recommended by pyparsing
float_number = Regex(r'[-+]?[0-9]*\.?[0-9]+([eE][-+]?[0-9]+)?') \
regex_after_decimal = r'([0-9]*\.?[0-9]+([eE][-+]?[0-9]+)?)'
float_number = Regex(r'[-+]?([0-9]+\.(?!([0-9]|[eE])))|{0}'.format(regex_after_decimal)) \
.setParseAction(lambda t: [float(t[0])])
# symbol name, e.g., phase name, function name
symbol_name = Word(alphanums+'_:', min=1)
Expand Down
15 changes: 15 additions & 0 deletions pycalphad/tests/test_database.py
Expand Up @@ -406,3 +406,18 @@ def test_tdb_missing_terminator_element():
FUNCTION EMBCCTI 298.15 -39.72; 6000 N !"""
Database(tdb_str)


def test_database_parsing_of_floats_with_no_values_after_decimal():
"""Floats with no values after the decimal should be properly parsed (gh-143)"""
tdb_string = """$ The element has no values after the decimal in '5004.'
ELEMENT CU FCC_A1 63.546 5004. 33.15 !"""
dbf = Database.from_string(tdb_string, fmt='tdb')
assert "CU" in dbf.elements


def test_database_parsing_of_floats_with_multiple_leading_zeros():
"""Floats with multiple leading zeros should be properly parsed (gh-143)"""
tdb_string = """$ The element has multiple leading zeros in '00.546'
ELEMENT CU FCC_A1 00.546 5004.0 33.15 !"""
dbf = Database.from_string(tdb_string, fmt='tdb')
assert "CU" in dbf.elements

0 comments on commit 0eac6ea

Please sign in to comment.