Repository: hgrecco/pint

Issue:
Absolute vs. Relative pressure
Dear all,

I could not find a differentiation between absolute and relative pressures in the list of units proposed by pint. Is this feature already implemented? If not, I think it would make sense to have it, as it is very common to differentiate between these two pressures. One could have units looking like `bar_relative` and `bar_absolute` for instance.

Thank you in advance and best regards,

Discussion:
jules-ch: @dalito can you rebase & push to resolve conflict on changes
jules-ch: Great, merging this.
Thanks @dalito 

Patch:
diff --git a/CHANGES b/CHANGES
index aa5443d..4ef06b7 100644
--- a/CHANGES
+++ b/CHANGES
@@ -4,6 +4,8 @@ Pint Changelog
 0.19 (unreleased)
 -----------------
 
+- Fix a bug for offset units of higher dimension, e.g. gauge pressure.
+  (Issue #1066, thanks dalito)
 - Fix type hints of function wrapper (Issue #1431)
 - Upgrade min version of uncertainties to 3.1.4
 - Fix setting options of the application registry (Issue #1403).
diff --git a/pint/registry.py b/pint/registry.py
index e3b5c77..77f167d 100644
--- a/pint/registry.py
+++ b/pint/registry.py
@@ -71,7 +71,7 @@ from . import registry_helpers, systems
 from ._typing import F, QuantityOrUnitLike
 from .compat import HAS_BABEL, babel_parse, tokenizer
 from .context import Context, ContextChain
-from .converters import LogarithmicConverter, ScaleConverter
+from .converters import ScaleConverter
 from .definitions import (
     AliasDefinition,
     Definition,
@@ -1463,10 +1463,10 @@ class NonMultiplicativeRegistry(BaseRegistry):
 
         return None
 
-    def _add_ref_of_log_unit(self, offset_unit, all_units):
+    def _add_ref_of_log_or_offset_unit(self, offset_unit, all_units):
 
         slct_unit = self._units[offset_unit]
-        if isinstance(slct_unit.converter, LogarithmicConverter):
+        if slct_unit.is_logarithmic or (not slct_unit.is_multiplicative):
             # Extract reference unit
             slct_ref = slct_unit.reference
             # If reference unit is not dimensionless
@@ -1534,13 +1534,13 @@ class NonMultiplicativeRegistry(BaseRegistry):
             value = self._units[src_offset_unit].converter.to_reference(value, inplace)
             src = src.remove([src_offset_unit])
             # Add reference unit for multiplicative section
-            src = self._add_ref_of_log_unit(src_offset_unit, src)
+            src = self._add_ref_of_log_or_offset_unit(src_offset_unit, src)
 
         # clean dst units from offset units
         if dst_offset_unit:
             dst = dst.remove([dst_offset_unit])
             # Add reference unit for multiplicative section
-            dst = self._add_ref_of_log_unit(dst_offset_unit, dst)
+            dst = self._add_ref_of_log_or_offset_unit(dst_offset_unit, dst)
 
         # Convert non multiplicative units to the dst.
         value = super()._convert(value, src, dst, inplace, False)


Test patch:
diff --git a/pint/testsuite/test_issues.py b/pint/testsuite/test_issues.py
index ed781b7..55723c3 100644
--- a/pint/testsuite/test_issues.py
+++ b/pint/testsuite/test_issues.py
@@ -717,6 +717,17 @@ class TestIssues(QuantityTestCase):
                 q = ureg.Quantity(1, "nm")
                 q.to("J")
 
+    def test_issue1066(self):
+        """Verify calculations for offset units of higher dimension"""
+        ureg = UnitRegistry()
+        ureg.define("barga = 1e5 * Pa; offset: 1e5")
+        ureg.define("bargb = 1 * bar; offset: 1")
+        q_4barg_a = ureg.Quantity(4, ureg.barga)
+        q_4barg_b = ureg.Quantity(4, ureg.bargb)
+        q_5bar = ureg.Quantity(5, ureg.bar)
+        helpers.assert_quantity_equal(q_4barg_a, q_5bar)
+        helpers.assert_quantity_equal(q_4barg_b, q_5bar)
+
     def test_issue1086(self):
         # units with prefixes should correctly test as 'in' the registry
         assert "bits" in ureg