diff --git a/CHANGELOG.md b/CHANGELOG.md index 9483965..559d7ef 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,13 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## Unreleased + +### Fixed + +- `Solution.get_total_amount`: Bugfix that would cause the method to fail if + mass-based units such as mg/L or ppm were requested. + ## [0.12.0] - 2024-02-15 ### Added @@ -19,7 +26,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Fixed -- `Solution.__add_`: Bugfix in the addition operation `+` that could cause problems with +- `Solution.__add__`: Bugfix in the addition operation `+` that could cause problems with child classes (i.e., classes that inherit from `Solution`) to work improperly ### Changed diff --git a/src/pyEQL/solution.py b/src/pyEQL/solution.py index 4ef6258..bb9c2cc 100644 --- a/src/pyEQL/solution.py +++ b/src/pyEQL/solution.py @@ -1204,7 +1204,7 @@ def get_total_amount(self, element: str, units) -> Quantity: "[mass]/[length]**3", "[mass]/[mass]", ): - TOT += amt * ion.to_weight_dict["el"] # returns {el: wt fraction} + TOT += amt * ion.to_weight_dict[el] # returns {el: wt fraction} return TOT diff --git a/tests/test_solution.py b/tests/test_solution.py index 921b248..000c79e 100644 --- a/tests/test_solution.py +++ b/tests/test_solution.py @@ -392,7 +392,7 @@ def test_components_by_element(s1, s2): def test_get_total_amount(s2): - assert np.isclose(s2.get_total_amount("Na(1)", "mol").magnitude, 8) + assert np.isclose(s2.get_total_amount("Na(1)", "g").magnitude, 8 * 58, 44) assert np.isclose(s2.get_total_amount("Na", "mol").magnitude, 8) sox = Solution({"Fe+2": "10 mM", "Fe+3": "40 mM", "Cl-": "50 mM"}, pH=3) assert np.isclose(sox.get_total_amount("Fe(2)", "mol/L").magnitude, 0.01)