From 079b35afb87fabe5180ba9fe14932e755c014373 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jules=20Ch=C3=A9ron?= Date: Sat, 15 Jan 2022 17:43:31 +0100 Subject: [PATCH] Fix 1427: Keep track of exponent reduction --- pint/quantity.py | 2 ++ pint/testsuite/test_quantity.py | 3 +++ 2 files changed, 5 insertions(+) diff --git a/pint/quantity.py b/pint/quantity.py index 138e17aa6..cfc5d93bf 100644 --- a/pint/quantity.py +++ b/pint/quantity.py @@ -771,6 +771,8 @@ def _get_reduced_units(self, units): if unit1 not in units: continue for unit2 in units: + # get exponent after reduction + exp = units[unit1] if unit1 != unit2: power = self._REGISTRY._get_dimensionality_ratio(unit1, unit2) if power: diff --git a/pint/testsuite/test_quantity.py b/pint/testsuite/test_quantity.py index b5413f4c1..998a53daa 100644 --- a/pint/testsuite/test_quantity.py +++ b/pint/testsuite/test_quantity.py @@ -642,6 +642,9 @@ def test_to_reduced_units(self): q.to_reduced_units(), self.Q_([3000.0, 4000.0], "ms**2") ) + q = self.Q_(0.5, "g*t/kg") + helpers.assert_quantity_equal(q.to_reduced_units(), self.Q_(0.5, "kg")) + class TestQuantityToCompact(QuantityTestCase): def assertQuantityAlmostIdentical(self, q1, q2):