-
Notifications
You must be signed in to change notification settings - Fork 468
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
Testing types and shapes across modules fails #629
Comments
Hi! there seems to be several different questions here. The way to check if a variables is an instance of Quantities, the way to do it is: >>> ureg = pint.UnitRegistry()
>>> isinstance(x, ureg.Quantity) Regarding heterogenous list of Quantitities, that is not a problem. What you cannot do is a heterogenous numpy array quantity. i.e. numpy arrays can be the magnitude of a quantity and therefore all elements have the same units Regarding creating code that can handle values with and without units, you can use wraps with Finally, if you want to use pint in different projects we are trying to create a better solution for that (see #623) |
This is very helpful. I will refactor my application code and come back to close the issue or ask more questions as things go. |
Ok, I changed my code to use the recommended
in this fork of Pint's test folder. I created a temporary variable called The calling code is
in this file. It fails with the following messages:
I'll be grateful for any advice. |
I'm going to try a 'duck typing' technique as that seems to be the preferred method in Python for dispatching on types. Still, I am curious why type signatures would change across modules. |
This turned out to be my misunderstanding: testing the quantities created against one Registry against the units type from another Registry. |
If I create a
units.Quantity
in one module and test its type in another module, I get failures (see this test in a fork of pint). This failure makes it more difficult to write polymorphic library code that can handle values with and without units.I can work around this non-robustly by testing a string representation of the type.
If I create a heterogeneous list of
units.Quantity
in one module and test itsnumpy.shape
in another module, I get exceptions raised innumpy
. (see this test in the same fork)This is more serious and no quick work-around is obvious.
It's possible that these failures simply reflect my misunderstandings of the depths of
import
and ofnumpy
types and are not defects in pint in any way. However, the things I want to do (create stuff in one module and test it in another module) seem intuitively reasonable and I was surprised by the failures.EDIT: I added another repo that does cross-module type checking without the errors I see from pint.
The text was updated successfully, but these errors were encountered: