Skip to content

Commit

Permalink
Merge pull request #107 from KingsburyLab/bugfix
Browse files Browse the repository at this point in the history
Solution.get_total_amount: bugfix for aliased units like ppm
  • Loading branch information
rkingsbury authored Feb 25, 2024
2 parents 8e7279a + 84eaa58 commit c43b2e6
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
9 changes: 8 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,20 @@ 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).

## [0.12.2] - 2024-02-25

### Fixed

- `Solution.get_total_amount`: Fix bug that would cause the method to fail if
units with names not natively understood by `pint` (e.g., 'ppm') were passed.

## [0.12.1] - 2024-02-25

### Fixed

- `Solute.from_formula`: Fix bug in which an uncaught exception could occur when
if `pymatgen` failed to guess the oxidation state of a solute. (Issue #103 - thanks to @xiaoxiaozhu123 for reporting).
- `Solution.get_total_amount`: Bugfix that would cause the method to fail if
- `Solution.get_total_amount`: Fix bug 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
Expand Down
2 changes: 1 addition & 1 deletion src/pyEQL/solution.py
Original file line number Diff line number Diff line change
Expand Up @@ -1165,7 +1165,7 @@ def get_total_amount(self, element: str, units) -> Quantity:
--------
get_amount
"""
TOT: Quantity = ureg.Quantity(f"0 {units}")
TOT: Quantity = 0

# standardize the element formula
el = str(Element(element.split("(")[0]))
Expand Down
1 change: 1 addition & 0 deletions tests/test_solution.py
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,7 @@ def test_components_by_element(s1, s2):
def test_get_total_amount(s2):
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)
assert np.isclose(s2.get_total_amount("Na", "ppm").magnitude, 4 * 23300, rtol=0.02)
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)
assert np.isclose(sox.get_total_amount("Fe(3)", "mol/L").magnitude, 0.04)
Expand Down

0 comments on commit c43b2e6

Please sign in to comment.