Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Units discrepancies between __init__ and get_amount #128

Open
rkingsbury opened this issue Apr 11, 2024 · 0 comments
Open

Units discrepancies between __init__ and get_amount #128

rkingsbury opened this issue Apr 11, 2024 · 0 comments

Comments

@rkingsbury
Copy link
Member

It appears that certain units which are supported by get_amount (including "%" and "ppb") are not supported in the __init__ method. Ideally, __init__ should be able to interpret the full set of units that can be retrieved via get_amount.

>>> s=Solution({'Ca+2': '1000 ppb'})
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/ryan/mambaforge/envs/skagit2/lib/python3.12/site-packages/pyEQL/solution.py", line 250, in __init__
    self.add_solute(k, v)
  File "/home/ryan/mambaforge/envs/skagit2/lib/python3.12/site-packages/pyEQL/solution.py", line 1213, in add_solute
    if ureg.Quantity(amount).dimensionality in (
       ^^^^^^^^^^^^^^^^^^^^^
  File "/home/ryan/mambaforge/envs/skagit2/lib/python3.12/site-packages/pint/facets/plain/quantity.py", line 205, in __new__
    inst = ureg.parse_expression(value)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/ryan/mambaforge/envs/skagit2/lib/python3.12/site-packages/pint/facets/plain/registry.py", line 1388, in parse_expression
    return build_eval_tree(gen).evaluate(_define_op)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/ryan/mambaforge/envs/skagit2/lib/python3.12/site-packages/pint/pint_eval.py", line 385, in evaluate
    self.right.evaluate(define_op, bin_op, un_op),
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/ryan/mambaforge/envs/skagit2/lib/python3.12/site-packages/pint/pint_eval.py", line 396, in evaluate
    return define_op(self.left)
           ^^^^^^^^^^^^^^^^^^^^
  File "/home/ryan/mambaforge/envs/skagit2/lib/python3.12/site-packages/pint/facets/plain/registry.py", line 1386, in _define_op
    return self._eval_token(s, case_sensitive=case_sensitive, **values)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/ryan/mambaforge/envs/skagit2/lib/python3.12/site-packages/pint/facets/plain/registry.py", line 1295, in _eval_token
    {self.get_name(token_text, case_sensitive=case_sensitive): 1}
     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/ryan/mambaforge/envs/skagit2/lib/python3.12/site-packages/pint/facets/plain/registry.py", line 647, in get_name
    raise UndefinedUnitError(name_or_alias)
pint.errors.UndefinedUnitError: 'ppb' is not defined in the unit registry
>>> s=Solution({'Ca+2': '1 ppm'})
>>> s.get_amount('Ca+2', 'ppb')
<Quantity(997.0486623989358, 'microgram / liter')>
>>> s.get_amount('Ca+2', '%')
<Quantity(9.999989981941417e-05, 'dimensionless')>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant