Replies: 1 comment 1 reply
-
Cool! What I have found to be a solution to "but don't know where it could broke" is to add functionality in a piecewise manner. i.e. make a narrow list of what you want to support and build checkers for those. Then raise an Exception is a given check is not passed. You can always add more functionality once it is released, but is difficult to remove it (even if it is broken as people might depend on it). Build a python package ( |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hello,
I would like to use pint along side the sympy package (read as I prefer to use pint, but sympy need its own object to function properly) and I was looking at the solution proposed in the issue 606.
I think that solution is not well suited for my needs because it doesn't convert the pint units in compatible sympy units, but just in free symbol, so that resulting expression cannot be simplified to a preferred unit (e.g. it wouldn't know that
1 m
equal to100 cm
).I worked upon that example and created a function that will convert a pint's Quantity to a sympy's Quantity:
The function checks if a unit exist in the sympy module, add it if it is missing, and the convert to simpy's Quantity. This will take care of the unit that are multiple of default unit, which usually are already presents in pint, but not in sympy. For example the kilonewton is not a default unit in sympy module.
b
is a valid sympy's quantity and can be converted toN
:The
kilonewton
is now been added to sympy_units module and is available assympy_units.kilonewton
andsympy_units.kN
This also works for derived units, such as density
To be extra juicy, I've extended the pint's Quantity and Unit following the example of the issue 606. Now pint quantity can be used directly in sympy expression:
I think I am onto something here, but needs some more polish. It seems to suit me well for my need, but don't know where it could broke (e.g. it doesn't handle the
kgf
because is not a simple prefix multiplied a unit in the module)Beta Was this translation helpful? Give feedback.
All reactions