Skip to content

Commit

Permalink
use dict comprehension; doc update; changelog update
Browse files Browse the repository at this point in the history
  • Loading branch information
DhruvDuseja committed Oct 20, 2023
1 parent 1087cc3 commit 7f6fff3
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ 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]

### Added

- `format_solutes_dict()` method added into the utils module to help format solutes dictionaries with a unit.

## [0.9.0] - 2023-10-17

### Added
Expand Down
9 changes: 3 additions & 6 deletions src/pyEQL/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,21 +40,18 @@ def format_solutes_dict(solute_dict: dict, units: str):
Args:
solute_dict: The dictionary to format. This must be of the form dict{str: Number}
e.g. {"Na+": 0.5, "Cl-": 0.9}
units: The units to use for the solute.
units: The units to use for the solute. e.g. "mol/kg"
Returns:
A formatted solute dictionary.
Raises:
TypeError if `solute_dict` is invalid.
TypeError if `solute_dict` is not a dictionary.
"""
if not isinstance(solute_dict, dict):
raise TypeError("solute_dict must be a dictionary. Refer to the doc for proper formatting.")

for key, value in solute_dict.items():
solute_dict[key] = f"{value!s} {units}"

return solute_dict
return {key: f"{value!s} {units}" for key, value in solute_dict.items()}


class FormulaDict(UserDict):
Expand Down

0 comments on commit 7f6fff3

Please sign in to comment.