0

The context for this question is that, using pint to parse input from users, I don't want those users to have to worry about delta vs non-delta units. I also know, for each quantity, whether it should be interpreted as a delta or non-delta unit.

So, for example, whether I get "2 degC" or "2 delta_degC" (or "2°C", or "2Δ°C", etc, or actual Quantity objects with corresponding units) from a user, I'd like the unit to be interpreted as delta_degC, with the same magnitude.

However, it's not clear how to convert between the two reasonably, for example, to go from 2 degC to 2 delta_degC. This is what as_delta does when parsing units, but it does not work outside of the string parser, and it only converts in certain multiple-unit contexts.

  • Normal conversion with or without autoconvert_offset_to_baseunit appears to autoconvert to the base unit first, giving potentially unexpected results (Q_(2, 'degC').to('delta_degC') == Q_(275.15, 'delta_degC')).

  • Subtraction by 0 degC works only if the Quantity doesn't already have a delta unit.

  • Direct modification of the string would fail in many contexts (eg, custom units, different aliases).

  • Following the example of parse_units with as_delta could produce a working function, but this would use be tricky to get right in a way that wouldn't be likely to break with pint updates.

Is there an obvious way to do this as_delta-like reinterpretation that I'm missing? Or is this something where I should discuss adding a way to do this to pint?

cge
  • 9,552
  • 3
  • 32
  • 51

0 Answers0