From 8b1a806c94140a4f26006a2fb6d2222c43286702 Mon Sep 17 00:00:00 2001 From: Sui Xiong Tay Date: Fri, 29 May 2026 13:54:12 -0400 Subject: [PATCH 1/3] handle np.nan --- src/pyEQL/utils.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/pyEQL/utils.py b/src/pyEQL/utils.py index 358a179c..f2072283 100644 --- a/src/pyEQL/utils.py +++ b/src/pyEQL/utils.py @@ -54,6 +54,10 @@ def _translate_pint_quantity(amount: str): return amount.magnitude, str(amount.units) match = re.match(r"^\s*([+-]?\d*\.?\d+(?:[eE][+-]?\d+)?)\s*(.*)$", amount) + + if match is None: + return amount + _value, _unit = match.groups() unit = translate_units(_unit) return (float(_value), unit) From 40eb5ee73da43cbb17958a57a7e496e1b071556f Mon Sep 17 00:00:00 2001 From: Sui Xiong Tay Date: Fri, 29 May 2026 14:04:33 -0400 Subject: [PATCH 2/3] constrain units --- src/pyEQL/utils.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/pyEQL/utils.py b/src/pyEQL/utils.py index f2072283..c30209a5 100644 --- a/src/pyEQL/utils.py +++ b/src/pyEQL/utils.py @@ -53,14 +53,17 @@ def _translate_pint_quantity(amount: str): if isinstance(amount, Quantity): return amount.magnitude, str(amount.units) - match = re.match(r"^\s*([+-]?\d*\.?\d+(?:[eE][+-]?\d+)?)\s*(.*)$", amount) + if "ppm" in amount or "ppb" in amount or "ppt" in amount or amount.strip().endswith("m"): + match = re.match(r"^\s*([+-]?\d*\.?\d+(?:[eE][+-]?\d+)?)\s*(.*)$", amount) - if match is None: - return amount + if match is None: + return amount - _value, _unit = match.groups() - unit = translate_units(_unit) - return (float(_value), unit) + _value, _unit = match.groups() + unit = translate_units(_unit) + return float(_value), unit + + return amount @lru_cache From a929b5e6a0430abe5e9325d5707d7e93829b3e15 Mon Sep 17 00:00:00 2001 From: Sui Xiong Tay Date: Fri, 29 May 2026 14:17:34 -0400 Subject: [PATCH 3/3] handle ** --- src/pyEQL/utils.py | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/src/pyEQL/utils.py b/src/pyEQL/utils.py index c30209a5..442b0336 100644 --- a/src/pyEQL/utils.py +++ b/src/pyEQL/utils.py @@ -53,17 +53,16 @@ def _translate_pint_quantity(amount: str): if isinstance(amount, Quantity): return amount.magnitude, str(amount.units) - if "ppm" in amount or "ppb" in amount or "ppt" in amount or amount.strip().endswith("m"): - match = re.match(r"^\s*([+-]?\d*\.?\d+(?:[eE][+-]?\d+)?)\s*(.*)$", amount) + match = re.match(r"^\s*([+-]?\d*\.?\d+(?:[eE][+-]?\d+)?)\s*(.*)$", amount) - if match is None: - return amount + if match is None: + return amount - _value, _unit = match.groups() - unit = translate_units(_unit) - return float(_value), unit - - return amount + _value, _unit = match.groups() + # handle python ** expression in Pint quantity + _value = eval(_value) if "**" in _value else float(_value) + unit = translate_units(_unit) + return (float(_value), unit) @lru_cache