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

Bug in Angle Dimensionality #2047

Open
rbreslavsky opened this issue Aug 20, 2024 · 5 comments
Open

Bug in Angle Dimensionality #2047

rbreslavsky opened this issue Aug 20, 2024 · 5 comments

Comments

@rbreslavsky
Copy link

I noticed an issue with regards to angle dimensionality. For one, when working with degrees to some exponent, n, pint does not distinguish degrees ** n from degrees. Furthermore, I can convert to degrees from degrees ** n, but this changes the numbers in a way that is obfuscated.

import pint

ureg = pint.UnitRegistry()

test = 5.0 * ureg('deg')
test_squared = test ** 2

Then I get:

In: test_squared
Out: <Quantity(25.0, 'degree ** 2')>

In: test_squared.is_compatible_with('deg')
Out: True

In: test_squared.to('deg')
Out: <Quantity(0.436332313, 'degree')>

The last output has converted <Quantity(25.0, 'degree')> to a radian equivalent, which was not the intent.

@jules-ch
Copy link
Collaborator

Do you have a physical example or use case in mind ?

This comes from the opinionated choice to treat angle as dimensionless:
https://pint.readthedocs.io/en/stable/user/angular_frequency.html

Difficult to treat this, I'd say. what would you have expected there ?

@jules-ch
Copy link
Collaborator

It is just a matter of convention, but conversion for steradian are correct when dealing with degrees squared:

>>> test = 180**2/math.pi**2 * ureg('deg')**2
>>> test.to("sr")
<Quantity(1.0, 'steradian')>

@jules-ch
Copy link
Collaborator

Related #1288

@rbreslavsky
Copy link
Author

rbreslavsky commented Dec 10, 2024

Thanks for taking the time to respond. This occurrence actually happened due to a bug in some code where a pint.Quantity of unit degrees was multiplied by ureg('deg') a second time.

The problem is that I tried to implement a check to make sure dimensionality was correct (using .is_compatible_with()). This check failed, and then I was allowed to strip units using .m_as() in another function, but that action effectively converted the answer to radians.

I think an error of some sort would be useful here (for example, when attempting to convert a non-radian angular dimension of an nth power to a root of itself). Could that be accommodated for angles? I know it's a niche issue, but pint has been fantastic at avoiding this kind of problem elsewhere.

@andrewgsavage
Copy link
Collaborator

possibly a warning yes, I had a similar idea here:
#1554

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