Skip to content

Commit d135609

Browse files
committed
Merge branch '0.8.x' of github.com:bjodah/chempy into 0.8.x
2 parents 3a32480 + b55a3d0 commit d135609

File tree

2 files changed

+8
-12
lines changed

2 files changed

+8
-12
lines changed

chempy/util/parsing.py

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ def _get_formula_parser():
9696
| '{' formula '}'
9797
| '[' formula ']' ) count prime charge?
9898
formula :: term+
99-
hydrate :: ( '.' | '\u00B7' | '*' ) count? formula
99+
hydrate :: ( '..' | '\u00B7' | '.' ) count? formula
100100
state :: '(' ( 's' | 'l' | 'g' | 'aq' | 'cr' ) ')'
101101
compound :: count formula hydrate? state?
102102
@@ -115,7 +115,7 @@ def _get_formula_parser():
115115
| '{' formula '}'
116116
| '[' formula ']' ) count prime charge?
117117
formula :: term+
118-
hydrate :: ( '..' | '\u00B7' | '*' ) count? formula
118+
hydrate :: ( '..' | '\u00B7' | '.' ) count? formula
119119
state :: '(' ( 's' | 'l' | 'g' | 'aq' | 'cr' ) ')'
120120
compound :: count formula hydrate? state?
121121
"""
@@ -378,7 +378,7 @@ def formula_to_composition(
378378
True
379379
>>> formula_to_composition('.NHO-(aq)') == {0: -1, 1: 1, 7: 1, 8: 1}
380380
True
381-
>>> formula_to_composition('Na2CO3*7H2O') == {11: 2, 6: 1, 8: 10, 1: 14}
381+
>>> formula_to_composition('Na2CO3..7H2O') == {11: 2, 6: 1, 8: 10, 1: 14}
382382
True
383383
384384
"""
@@ -387,10 +387,10 @@ def formula_to_composition(
387387

388388
stoich_tok, chg_tok = _formula_to_parts(formula, prefixes, suffixes)[:2]
389389
tot_comp = {}
390-
if ".." in stoich_tok:
391-
parts = stoich_tok.split("..")
392-
elif "\u00b7" in stoich_tok:
390+
if "\u00b7" in stoich_tok:
393391
parts = stoich_tok.split('\u00b7')
392+
elif '..' in stoich_tok:
393+
parts = stoich_tok.split("..")
394394
elif '.' in stoich_tok:
395395
warnings.warn(
396396
("dot is ambiguous in chempy-0.8.x, prefer '*' or '\u00b7' for complexes."
@@ -399,7 +399,7 @@ def formula_to_composition(
399399
)
400400
parts = stoich_tok.split('.')
401401
else:
402-
parts = list(filter(len, internal_asterisk.split(stoich_tok)))
402+
parts = [stoich_tok]
403403

404404
for idx, stoich in enumerate(parts):
405405
if idx == 0:
@@ -536,9 +536,6 @@ def to_reaction(line, substance_keys, token, Cls, globals_=None, **kwargs):
536536
)
537537

538538

539-
internal_asterisk = re.compile(r"([^\s\*]+)\*([a-zA-Z0-9]+)")
540-
541-
542539
def _formula_to_format(
543540
sub,
544541
sup,
@@ -549,7 +546,6 @@ def _formula_to_format(
549546
):
550547
parts = _formula_to_parts(formula, prefixes.keys(), suffixes)
551548
parts0 = parts[0].replace("..", "\u00B7")
552-
parts0 = internal_asterisk.sub("\u00B7", parts0)
553549
if '.' in parts0:
554550
warnings.warn(
555551
("dot is ambiguous in chempy-0.8.x, prefer '*' or '' for complexes."

chempy/util/tests/test_parsing.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -724,7 +724,7 @@ def test_composition_dot_as_crystal_water_chempy08x():
724724
as floating point delimiter in fractional stoichiometric coefficients."""
725725
ref = {30: 1, 7: 2, 8: 12, 1: 12}
726726
assert formula_to_composition('Zn(NO3)2{}6H2O'.format('\u00B7')) == ref
727-
assert formula_to_composition('Zn(NO3)2*6H2O') == ref
727+
assert formula_to_composition('Zn(NO3)2..6H2O') == ref
728728
# https://docs.pytest.org/en/7.1.x/how-to/capture-warnings.html#ensuring-code-triggers-a-deprecation-warning
729729
with pytest.deprecated_call():
730730
assert formula_to_composition('Zn(NO3)2.6H2O') == ref

0 commit comments

Comments
 (0)