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

is_compatible_with ignores active contexts #1424

Closed
keewis opened this issue Nov 24, 2021 · 0 comments · Fixed by #1426
Closed

is_compatible_with ignores active contexts #1424

keewis opened this issue Nov 24, 2021 · 0 comments · Fixed by #1426

Comments

@keewis
Copy link
Contributor

keewis commented Nov 24, 2021

While working on #1421 I noticed that is_compatible_with allows working with contexts, but they have to be passed explicitly: contexts that were activated using ureg.context (both when used as a function and as a context manager) will be ignored:

In [6]: ureg = pint.UnitRegistry()
   ...: 
   ...: a = 532.0 * ureg.nm
   ...: b = 563.5 * ureg.terahertz
   ...: 
   ...: with ureg.context("sp"):
   ...:     print(a.to(ureg.terahertz))
   ...:     assert a.is_compatible_with(b), "not compatible"
   ...: 
563.5196578947367 terahertz
---------------------------------------------------------------------------
AssertionError                            Traceback (most recent call last)
<ipython-input-6-8eaa63cfa960> in <module>
      6 with ureg.context("sp"):
      7     print(a.to(ureg.terahertz))
----> 8     assert a.is_compatible_with(b), "not compatible"
      9 

AssertionError: not compatible

(see also #1421 (comment))

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

Successfully merging a pull request may close this issue.

1 participant