3

I sometimes use the pint library to display civil engineering calculations.

For these calculations, there are times when I want a quantity displayed a certain way in order to make it clear what the quantity represents. But when using pint, the units get automatically reduced, making things less clear.

Some examples:

  • "moment per unit length": changed from kip·ft/ft to kip
  • "area per unit length": changed from in²/in to in
  • "moment of inertia per length": changed from in⁴/in to in³
  • "slope": changed from in/in to unitless

Code illustrating the first example:

>>> import pint
>>> u = pint.UnitRegistry(system='US')
>>> x = 100*u.kip*u.ft/u.ft
>>> f'{x:~P}'
'100.0 kip'

Can I prevent this unit simplification, and get the units to display the way I want?

Rick
  • 43,029
  • 15
  • 76
  • 119
  • It appears the answer [might be no](https://github.com/hgrecco/pint/issues/389). – Rick Jul 11 '19 at 14:05
  • 2
    I have the same question with regards to production intensity. In the corp sustainability space, people want to know the ratio of CO2 emitted per unit of production. People talk about `t CO2 / t Steel' and are not expecting an intensity metric of 'CO2 / Steel'. – Michael Tiemann Feb 23 '22 at 11:02

0 Answers0