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

Percent (%) sign #857

Closed
crusaderky opened this issue Aug 29, 2019 · 2 comments
Closed

Percent (%) sign #857

crusaderky opened this issue Aug 29, 2019 · 2 comments

Comments

@crusaderky
Copy link
Contributor

crusaderky commented Aug 29, 2019

After defining:

import pint
ureg = pint.UnitRegistry()
ureg.define("% = 0.01 count = percent")
ureg.define("%% = 0.001 count = per_mille")
ureg.define("ppm = 1e-6 count = parts_per_million")

This works:

>>> ureg("0.1 percent").to("ppm")
1000.0 ppm

But % and %% don't:

>>> ureg("0.1%").to("ppm")
AttributeError: 'float' object has no attribute 'to'
>>> ureg("0.1%")
0.1
@jthielen
Copy link
Contributor

I think this issue has been around for a while (see #429), and there are many different workarounds. For example, MetPy has worked around it outside of pint (see Unidata/MetPy#1057).

But, looking back, @hgrecco's comment about having the pre-processor be pluggable/extensible as a way to resolve this (#429 (comment)) connects this to #851 and #799. Based on all this, I think I'm going to try putting together a PR for an extensible pre-processor sometime soon.

@crusaderky
Copy link
Contributor Author

Indeed duplicates #429

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

2 participants