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

parse_pattern doesn´t parse compound units #2003

Open
keigezellig opened this issue Jun 1, 2024 · 4 comments
Open

parse_pattern doesn´t parse compound units #2003

keigezellig opened this issue Jun 1, 2024 · 4 comments

Comments

@keigezellig
Copy link

keigezellig commented Jun 1, 2024

When using parse_pattern with compound units in the pattern (e.g. 'meter per second'), it won´t parse.

Example:

>>> input = '44 mpsec'
>>> pattern = '{meter per second} mpsec´                 //Tried also 'meter / second' but didn´t work either.
>>> ureg.parse_pattern(input_string=input, pattern=pattern)
>>> []                                                   //Would expect <Quantity(44, 'meter / second')> here 

With a single unit in the pattern (like 'meter') it does work fine

@yerkoescalona
Copy link

Hello, this is because you are missing the underscore characters associated with the unit definition

It works with:

>>> input = '44 mpsec'
>>> pattern = '{meter_per_second} mpsec'
>>> ureg.parse_pattern(input_string=input, pattern=pattern)
[44.0 <Unit('meter_per_second')>]

Greetings

@andrewgsavage
Copy link
Collaborator

perhaps we should add some regex to parse_pattern so it replaces " per " with " / "?

@keigezellig
Copy link
Author

@yerkoescalona Ok, that was not very obvious (i was already looking for the unit definitions in the code, but i couldn´t find them, maybe we could put a description of all unit definitions somewhere in the documentation?)

@andrewgsavage
Copy link
Collaborator

At the top of the tutorial

https://pint.readthedocs.io/en/stable/getting/tutorial.html

If no parameters are given to the constructor, the UnitRegistry is populated with the default list of units and prefixes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants