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

Issue converting to % #1758

Closed
lafrech opened this issue Apr 28, 2023 · 3 comments
Closed

Issue converting to % #1758

lafrech opened this issue Apr 28, 2023 · 3 comments
Labels

Comments

@lafrech
Copy link

lafrech commented Apr 28, 2023

I'm trying to use the new % unit introduced in #1661.

While it works to define a quantity, that can then be converted to another dimensionless unit:

>>> ureg.Quantity(1, "%")
<Quantity(1, 'percent')>
>>> ureg.Quantity(1, "%").m_as("")
0.01

it doesn't seem to work the other way around.

>>> ureg.Quantity(1, "")
<Quantity(1, 'dimensionless')>
>>> ureg.Quantity(1, "").m_as("%")
pint.errors.DefinitionSyntaxError: missing unary operator "%"

Is this a known limitation? It doesn't seem consistent.

Looks like preprocessors apply to quantity definitions but not unit expressions in Quantity.to.

I think I have a workaround that at least solves my use case:

>>> ureg.Quantity(1, "").m_as(ureg.Unit("%"))
100.0

Perhaps this cast could be done somewhere in m_as, to or further down the way.

@hgrecco
Copy link
Owner

hgrecco commented Apr 29, 2023

confirmed

@mmarras
Copy link

mmarras commented Feb 13, 2024

confirmed

I think this can be closed with 0.23, no? I tried ureg.Quantity(1,'').to('%') and it works now.

@lafrech
Copy link
Author

lafrech commented Feb 13, 2024

Indeed, this seems to be fixed in 0.23.0.

Thanks.

@lafrech lafrech closed this as completed Feb 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants