Skip to content

Issue using currency symbols ($, €) #2015

@simaosr

Description

@simaosr

Hello,

I'm trying to use Pint 0.23 to handle currency conversion. I'm creating my currency units with

# Create UnitRegistry
ureg = UnitRegistry()

# Create currency dimension
ureg.define("USD = [currency]")
ureg.define("EUR = 1.14 USD = €")
ureg.define("GBP = 1.17 USD = £")

However, whenever I try to handle any unit defined using the symbol (alone), I get the following error:

Traceback (most recent call last):
File ", line 19, in
a = ureg("$")
File "venv\lib\site-packages\pint\facets\plain\registry.py", line 1388, in parse_expression
return build_eval_tree(gen).evaluate(_define_op)
File "venv\lib\site-packages\pint\pint_eval.py", line 566, in build_eval_tree
result, _ = _build_eval_tree(tokens, op_priority, 0, 0)
File "venv\lib\site-packages\pint\pint_eval.py", line 515, in _build_eval_tree
assert result is not None
AssertionError

If I try to use the symbol with another unit ("$/Mt" for example) I get the following error:

File "venv\lib\site-packages\pint\util.py", line 767, in from_string
ret = build_eval_tree(gen).evaluate(
File "venv\lib\site-packages\pint\pint_eval.py", line 392, in evaluate
raise DefinitionSyntaxError(f"missing unary operator '{op_text}'")
pint.errors.DefinitionSyntaxError: missing unary operator '/'

Has anyone faced this issue, or know how to handle this properly?

Thank you in advance.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions