From 2ef40502be90a3c8efbd019a0b014bf8f4aafc37 Mon Sep 17 00:00:00 2001 From: montmorillonite Date: Mon, 18 Sep 2023 05:59:33 +0800 Subject: [PATCH 1/5] Fix #218 --- chempy/chemistry.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/chempy/chemistry.py b/chempy/chemistry.py index f20f75bb..0543f0e2 100644 --- a/chempy/chemistry.py +++ b/chempy/chemistry.py @@ -574,7 +574,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." From 665ce84112570847647654c2330269d648167f25 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Ingvar=20Dahlgren?= Date: Mon, 18 Sep 2023 21:22:33 +0200 Subject: [PATCH 2/5] Tweak test-run in CI-job --- .github/workflows/lint_python.yml | 6 +++--- setup.cfg | 2 ++ 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/.github/workflows/lint_python.yml b/.github/workflows/lint_python.yml index 0351167b..a1ee05a7 100644 --- a/.github/workflows/lint_python.yml +++ b/.github/workflows/lint_python.yml @@ -9,6 +9,9 @@ jobs: with: python-version: 3.x - run: pip install --upgrade pip wheel + - run: pip install --editable . || pip install . + - run: pytest . + - run: pytest --doctest-modules . - run: pip install bandit "black[jupyter]" codespell flake8 flake8-2020 isort mypy pytest pyupgrade - run: bandit --recursive --skip B101,B102,B110,B112,B307,B404,B603,B607 . @@ -20,9 +23,6 @@ jobs: - run: flake8 . --count --exit-zero --max-complexity=66 --max-line-length=118 --show-source --statistics - run: isort --check-only --profile black . || true - - run: pip install --editable . || pip install . - run: mkdir --parents --verbose .mypy_cache - run: mypy --ignore-missing-imports --install-types --non-interactive . || true - - run: pytest . - - run: pytest --doctest-modules . - run: shopt -s globstar && pyupgrade --py37-plus **/*.py || true 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 From 90642e6191e7dff848772226aa09e36b8fe40406 Mon Sep 17 00:00:00 2001 From: montmorillonite Date: Wed, 20 Sep 2023 22:27:28 +0800 Subject: [PATCH 3/5] Test Reaction_check_integral --- chempy/tests/test_chemistry.py | 41 ++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/chempy/tests/test_chemistry.py b/chempy/tests/test_chemistry.py index 8c5aa811..22dffbd7 100644 --- a/chempy/tests/test_chemistry.py +++ b/chempy/tests/test_chemistry.py @@ -205,6 +205,47 @@ 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(): + + # this could be sympy.core.numbers.Integer + 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) From eff946ec8d85ae67bdebb726c79ab7c1f8966b83 Mon Sep 17 00:00:00 2001 From: montmorillonite Date: Wed, 20 Sep 2023 22:52:34 +0800 Subject: [PATCH 4/5] Rename test function name --- chempy/tests/test_chemistry.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/chempy/tests/test_chemistry.py b/chempy/tests/test_chemistry.py index 22dffbd7..af32c1b6 100644 --- a/chempy/tests/test_chemistry.py +++ b/chempy/tests/test_chemistry.py @@ -206,9 +206,8 @@ def test_Reaction_from_string__units(): @requires(parsing_library, units_library) -def test_Reaction_check_integral(): +def test_Reaction__check_integral(): - # this could be sympy.core.numbers.Integer Reaction(*balance_stoichiometry({"H2", "O2"}, {"H2O"})) class MyInt: @@ -266,7 +265,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) From 32e8afb0e180fe74aff1eefb83b3f0a14eda8bab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Ingvar=20Dahlgren?= Date: Tue, 23 Apr 2024 13:41:13 +0200 Subject: [PATCH 5/5] Update changelog --- .github/workflows/lint_python.yml | 5 ++--- CHANGES.rst | 9 +++++++++ 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/.github/workflows/lint_python.yml b/.github/workflows/lint_python.yml index 2fd2fbea..1bc77f30 100644 --- a/.github/workflows/lint_python.yml +++ b/.github/workflows/lint_python.yml @@ -9,9 +9,6 @@ jobs: with: python-version: 3.x - run: pip install --upgrade pip wheel - - run: pip install --editable . || pip install . - - run: pytest . - - run: pytest --doctest-modules . - run: pip install bandit "black[jupyter]" codespell flake8 flake8-2020 isort mypy pytest pyupgrade - run: bandit --recursive --skip B101,B102,B110,B112,B307,B404,B603,B607 . @@ -27,4 +24,6 @@ jobs: - run: pip install --editable . || pip install . - run: mkdir --parents --verbose .mypy_cache - run: mypy --ignore-missing-imports --install-types --non-interactive . || true + - run: pytest . + - run: pytest --doctest-modules . - run: shopt -s globstar && pyupgrade --py37-plus **/*.py || true 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.