Replies: 1 comment 2 replies
-
I see the why this may be surprising, but IMHO it is the only consistent behaviour: when multiplying with a unit, pint just creates a In this case you are using a string object as your magnitude, and the regular (string) operations are used. The alternative (pint implicitly casting the magnitude to some numerical value) would necessarily require lots of guesswork and oppinionated decisions by pint (e.g., should it cast to an int, or a float, or decimal or ndarray,...?) Furthermore, implicit casting would never be able to handle arbitrary custom types: consider, e.g. that you create a custom string type for parsing So it is better to follow the zen of python ("better explicit than implicit") and let the user cast the magnitude explicitly if needed before wrapping with pint. |
Beta Was this translation helpful? Give feedback.
-
Stumbled on this surprising behavior, can't tell if it's a bug, feature or undefined behavior:
Beta Was this translation helpful? Give feedback.
All reactions