From 97b78c419d9c45af5431cb76205b454039a5de63 Mon Sep 17 00:00:00 2001 From: David Linke Date: Fri, 8 Mar 2024 23:27:01 +0100 Subject: [PATCH] Fix conversion to multi-dimension offset units --- CHANGES | 4 ++-- pint/facets/nonmultiplicative/registry.py | 7 ++++++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/CHANGES b/CHANGES index 6b1d0484e..c53bcdb32 100644 --- a/CHANGES +++ b/CHANGES @@ -4,8 +4,8 @@ Pint Changelog 0.24 (unreleased) ----------------- -- Nothing changed yet. - +- Fix converting to offset units of higher dimension e.g. gauge pressure (#1949). +- 0.23 (2023-12-08) ----------------- diff --git a/pint/facets/nonmultiplicative/registry.py b/pint/facets/nonmultiplicative/registry.py index 67250ea48..e5e2791a6 100644 --- a/pint/facets/nonmultiplicative/registry.py +++ b/pint/facets/nonmultiplicative/registry.py @@ -193,7 +193,7 @@ def _add_ref_of_log_or_offset_unit( self, offset_unit: str, all_units: UnitsContainer ) -> UnitsContainer: slct_unit = self._units[offset_unit] - if slct_unit.is_logarithmic or (not slct_unit.is_multiplicative): + if slct_unit.is_logarithmic: # Extract reference unit slct_ref = slct_unit.reference @@ -205,6 +205,11 @@ def _add_ref_of_log_or_offset_unit( (u, e) = [(u, e) for u, e in slct_ref.items()].pop() # Add it back to the unit list return all_units.add(u, e) + + if not slct_unit.is_multiplicative: # is offset unit + # Extract reference unit + return slct_unit.reference + # Otherwise, return the units unmodified return all_units