diff --git a/CHANGES.rst b/CHANGES.rst index 0e009e35..a1fdea37 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -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. diff --git a/chempy/chemistry.py b/chempy/chemistry.py index 4b310912..aab723ff 100644 --- a/chempy/chemistry.py +++ b/chempy/chemistry.py @@ -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." diff --git a/chempy/tests/test_chemistry.py b/chempy/tests/test_chemistry.py index 2307be57..81df2800 100644 --- a/chempy/tests/test_chemistry.py +++ b/chempy/tests/test_chemistry.py @@ -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) @@ -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) diff --git a/setup.cfg b/setup.cfg index fa3794a5..7bb8b5de 100644 --- a/setup.cfg +++ b/setup.cfg @@ -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. @@ -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