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

Relative units with numpy integer division raises error #2109

Open
samwaseda opened this issue Jan 4, 2025 · 0 comments
Open

Relative units with numpy integer division raises error #2109

samwaseda opened this issue Jan 4, 2025 · 0 comments

Comments

@samwaseda
Copy link

It looks like an edge case, but I guess it's an error coming from pint, so I raise it here.

What obviously works

def f(x, y):
    return x / y

print(f(np.array([1]), np.array([2])))

Output: [0.5]

What raises an error

from pint import UnitRegistry

ureg = UnitRegistry()


@ureg.wraps("=A/B", ("=A", "=B"))
def f(x, y):
    return x / y

print(f(np.array([1.]) * ureg.angstrom, np.array([2.]) * ureg.second)) # This one works
print(f(np.array([1]) * ureg.angstrom, np.array([2]) * ureg.second)) # This one raises an error

Here's the error message: ValueError: Integers to negative integer powers are not allowed. It's not impossible to understand what it means, but since numpy automatically converts it to a float, I think pint should also support it.

I'm using version 0.24.4

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

1 participant