-
Notifications
You must be signed in to change notification settings - Fork 468
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
How should one parse unit names that are not valid identifiers? #554
Comments
The new parser should definitely allow this as we have decoupled from Python's eval. But we are still using the Python tokenizer. Notice this: >>> ureg.parse_expression('10%')
10 I think that the quickest way in your case will be to introduce a replacement rule '%' -> '* 0.01'. |
Also interesting:
|
Thanks @hgrecco , I'll give that a shot.
Well... that's 2 [mod] 4, so that doesn't surprise me. |
You can now add your own |
Perfect, thanks! |
I'm using
pint
to do checking and conversion of units for some database insertion code and I'm a bit confused about how to define the unit '%'.Basically, I have a set of weather observations coming in from multi-source input files that are attributed with units, and I'm stuffing them into a database table that may be attributed with different (but compatible) units.
In particular, we're pulling in relative humidity data that are attributed with the units "%" in the database.
Based on the comments in #226, I assumed that the new parser would allow units like " ' and %. But then in
pint
's test suite the test for this case seems to be intended to fail?Or am I reading that wrong?
Defining the unit '%' doesn't error out, but then trying to parse it does:
Is there some other way that I should be doing this? Thanks for any info that you can provide.
The text was updated successfully, but these errors were encountered: