Skip to content

Quantities or Pint #92

@scasagrande

Description

@scasagrande

In light of the discussions in issue #91 I think we should also take a look at if we want to continue to use quantities over alternatives like pint.

quantities is what we've been using, but that's mostly just because it was the best option we found.

Keeping Quantities Pros

  • Its what we're using, so not switching lets us focus on other stuff

Keeping Quantities Cons

  • hard numpy dependency
  • developers have no intention of adding the features that we'd like

Switching to Pint Pros

  • more active development
  • supports features like converting between kelvin and celsius
  • their issues pages seem to indicate that they'd like to support non-linear units like dBm
  • can remove numpy as a dependency

Switching to Pint Cons

  • a fuck ton of work, basically every file uses quantities
  • a little less straight forward to use for end users. With quantities all you need to do is import quantities as pq and you're good to go. With pint you have two lines you need to execute, along with a parameter in the second line if you want easy-to-use temperature units
  • using temperature units requires reading docs. Trying to do something like:
>>> import pint
>>> ureg = pint.UnitRegistry()
>>> foo = 3 * ureg.degC

isn't going to work. That's because addition/multiplication of non-absolute units are non-trivial. Their docs go into detail about this, and it makes sense after you read it. For example, if you have 10C + 10C, do you get 20C, or do you get 313C (293K+293K)? So instead, you have to do either:

>>> import pint
>>> ureg = pint.UnitRegistry()
>>> Q_ = ureg.Quantity
>>> foo = Q_(3, ureg.degC)

or

>>> import pint
>>> ureg = UnitRegistry(autoconvert_offset_to_baseunit = True)
>>> foo = 3 * ureg.degC

where this will automatically convert these units to kelvin when doing addition/multiplication.

More about that can be read at https://pint.readthedocs.org/en/0.7.2/nonmult.html

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions