Skip to content

Commit

Permalink
Merge pull request #105 from KingsburyLab/bugfix
Browse files Browse the repository at this point in the history
Solution.get_total_amount: bufix for mass based units
  • Loading branch information
rkingsbury authored Feb 25, 2024
2 parents c4964ca + 9209926 commit 6fea057
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
9 changes: 8 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/pyEQL/solution.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion tests/test_solution.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 6fea057

Please sign in to comment.