Skip to content
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

Fix gh 218 from montmorill #232

Merged
merged 7 commits into from
Apr 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
v0.9.0
======
- Fractional stoichiometries are now officially supported in parser (e.g. Fe2O3.14)
- Complexes/crystal water should now be delimited with '..' (fix by @jeremyagray)
- Unicode printing of subscript decimal point should now work (gh-223, fix by @jeremyagray)
- Substance class now has a __hash__ function (fix by @DNIIBOY)
- Unit per100eV now has correct repr (fix by @daankoning)
- Passing results from balance_stoichiometry into Reaction now works (gh-218, thanks @montmorill)

v0.8.3
======
- Fixes for latest version of quantities.
Expand Down
2 changes: 1 addition & 1 deletion chempy/chemistry.py
Original file line number Diff line number Diff line change
Expand Up @@ -583,7 +583,7 @@ def check_all_integral(self, throw=False):
for nam in "reac prod inact_reac inact_prod".split()
]:
for k, v in cont.items():
if v != type(v)(int(v)):
if v != int(v) and v != type(v)(int(v)):
if throw:
raise ValueError(
"Found a non-integer stoichiometric coefficient for %s in %s."
Expand Down
42 changes: 41 additions & 1 deletion chempy/tests/test_chemistry.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,46 @@ def test_Reaction_from_string__units():
Reaction.from_string("H2O -> H+ + OH-; 1e-4/M/s", "H2O H+ OH-".split())


@requires(parsing_library, units_library)
def test_Reaction__check_integral():

Reaction(*balance_stoichiometry({"H2", "O2"}, {"H2O"}))

class MyInt:
def __init__(self, __data):
self.__data = __data

def __eq__(self, other):
return self.__data == other

def __lt__(self, other):
return self.__data < other

def __int__(self):
return self.__data

def __rsub__(self, other):
return other - self.__data

class MyOne:
def __eq__(self, other):
return 1 == other

def __lt__(self, other):
return 1 < other

def __int__(self):
return 1

def __rsub__(self, other):
return other - 1

Reaction({"H2": MyInt(2), "O2": MyOne()}, {"H2O": 2})

with pytest.raises(ValueError):
Reaction({"H2": 1, "O2": 0.5}, {"H2O": 1})


@requires(parsing_library, units_library)
def test_Substance__molar_mass():
mw_water = Substance.from_formula("H2O").molar_mass(default_units)
Expand All @@ -227,7 +267,7 @@ def test_Equilibrium__as_reactions():


@requires(parsing_library)
def test_ReactioN__latex():
def test_Reaction__latex():
keys = "H2O H2 O2".split()
subst = {k: Substance.from_formula(k) for k in keys}
r2 = Reaction.from_string("2 H2O -> 2 H2 + O2", subst)
Expand Down
2 changes: 2 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ flake8-ignore =
# E222: Multiple spaces after operator.
# E226: Missing space around arithmetic operator.
# E251: unexpected spaces around keyword/parameter equals
# E721: do not compare types
# F401: Multiple imports on one line.
# F403: Module import not at top of file.
# W503: Break before binary operator; warn on breaking after.
Expand All @@ -36,6 +37,7 @@ flake8-ignore =
__init__.py F401 F403
arrhenius.py F401
chempy/*.* E226
chempy/chemistry.py E721
chempy/kinetics/tests/test_rates.py E221 E222 E251
chempy/properties/** E222
debye_huckel.py F401
Expand Down
Loading