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

String parsing to initiate Measurement object #1672

Closed
Cs137 opened this issue Nov 29, 2022 · 1 comment
Closed

String parsing to initiate Measurement object #1672

Cs137 opened this issue Nov 29, 2022 · 1 comment

Comments

@Cs137
Copy link

Cs137 commented Nov 29, 2022

I did not find any information on parsing strings in order to initiate a Measurement object in the pint documentation. The method described for the Quantity object shows an unwanted behaviour and creates a product if ± is used as separator between nominal value and uncertainty. In the case of +/-, a DefinitionSyntaxError is raised.

Example:

import pint

ureg = pint.UnitRegistry()

for item in ['123 g','123 ± 3 g', '123 +/- 3 g']:
    print(ureg(item))

Output:

123 gram
369 gram

---------------------------------------------------------------------------
DefinitionSyntaxError                     Traceback (most recent call last)
Input In [2], in <module>
      3 ureg = pint.UnitRegistry()
      5 for item in ['123 g','123 ± 3 g', '123 +/- 3 g']:
----> 6     print(ureg(item))

...

DefinitionSyntaxError: missing unary operator "/"

I used version 0.20.1 of pint in the example.

@jules-ch
Copy link
Collaborator

Closing in favour of #1611.

There is a PR addressing this waiting #1615

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

2 participants