From e84b013a75c3d958190fa7923bf272420dfa5710 Mon Sep 17 00:00:00 2001 From: Chengyu Liu Date: Wed, 22 Mar 2023 16:02:37 +0900 Subject: [PATCH 1/2] MAINT: fix unit conversion --- scimath/units/quantity.py | 3 +-- scimath/units/tests/test_units.py | 9 +++++++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/scimath/units/quantity.py b/scimath/units/quantity.py index 30e92c2..53ceedd 100644 --- a/scimath/units/quantity.py +++ b/scimath/units/quantity.py @@ -303,8 +303,7 @@ def propagate_data_changes(self): return # Replace the predecessor's data with converted data. - new_quantity = self.change_unit_system(predecessor.units) - predecessor.data = new_quantity.data + predecessor.data = units_convert(self.data, self.units, predecessor.units) # Recursively continue propagating. predecessor.propagate_data_changes() diff --git a/scimath/units/tests/test_units.py b/scimath/units/tests/test_units.py index 1107d34..8490816 100644 --- a/scimath/units/tests/test_units.py +++ b/scimath/units/tests/test_units.py @@ -197,6 +197,15 @@ def test_propagation(self): self.assertAlmostEqual(30., q1.data, 1, "Propagation test expected data 30, got %s" % str(q1.data)) + def test_propagation2(self): + """ Tests data propagation for a single converted quantity. """ + + q1 = Quantity(10.0, units='ft', family_name='depth') + q2 = q1.change_unit_system('METRIC') + q2.data = 2 * q2.data + q2.propagate_data_changes() + self.assertAlmostEqual(q1.data, 20.0) + def test_get_original(self): q1 = Quantity(10, units='m', family_name='depth') From 93123da1e3c613a334ca78f37691e7c3a6f1b332 Mon Sep 17 00:00:00 2001 From: Chengyu Liu Date: Wed, 22 Mar 2023 16:48:27 +0900 Subject: [PATCH 2/2] use new name for test propagation --- scimath/units/tests/test_units.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scimath/units/tests/test_units.py b/scimath/units/tests/test_units.py index 8490816..82e5de3 100644 --- a/scimath/units/tests/test_units.py +++ b/scimath/units/tests/test_units.py @@ -197,7 +197,7 @@ def test_propagation(self): self.assertAlmostEqual(30., q1.data, 1, "Propagation test expected data 30, got %s" % str(q1.data)) - def test_propagation2(self): + def test_propagation_to_imperial(self): """ Tests data propagation for a single converted quantity. """ q1 = Quantity(10.0, units='ft', family_name='depth')