From 3e393ff1dfc7befe1e6e3592642b076e192795cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jules=20Ch=C3=A9ron?= Date: Sun, 18 Sep 2022 12:36:40 +0200 Subject: [PATCH] Update quantity repr - Update CHANGES - Add test for repr - Update repr function to include magnitude repr & units --- CHANGES | 2 ++ pint/facets/plain/quantity.py | 5 +---- pint/testsuite/test_quantity.py | 13 ++++++++++++- 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/CHANGES b/CHANGES index 177c198f6..7b6ddc971 100644 --- a/CHANGES +++ b/CHANGES @@ -11,6 +11,8 @@ Pint Changelog (Issue #1030, #574) - Added angular frequency documentation page. - Move ASV benchmarks to dedicated folder. (Issue #1542) +- Change Quantity repr to include magnitude repr & units. + 0.19.2 (2022-04-23) ------------------- diff --git a/pint/facets/plain/quantity.py b/pint/facets/plain/quantity.py index 5e4f33ddb..34351767d 100644 --- a/pint/facets/plain/quantity.py +++ b/pint/facets/plain/quantity.py @@ -267,10 +267,7 @@ def __bytes__(self) -> bytes: return str(self).encode(locale.getpreferredencoding()) def __repr__(self) -> str: - if isinstance(self._magnitude, float): - return f"" - else: - return f"" + return f"" def __hash__(self) -> int: self_base = self.to_base_units() diff --git a/pint/testsuite/test_quantity.py b/pint/testsuite/test_quantity.py index c9b3fe9ee..463075fd2 100644 --- a/pint/testsuite/test_quantity.py +++ b/pint/testsuite/test_quantity.py @@ -121,7 +121,18 @@ def test_quantity_comparison_convert(self): def test_quantity_repr(self): x = self.Q_(4.2, UnitsContainer(meter=1)) assert str(x) == "4.2 meter" - assert repr(x) == "" + assert repr(x) == "" + x=self.Q_(2.9325156461464651456456545649) + assert repr(x) == "" + + @helpers.requires_numpy + def test_quantity_repr_numpy(self): + x = self.Q_(4.2) + assert repr(x) == "" + x = self.Q_(np.array(2.)) + assert repr(x) == "" + x = self.Q_(np.array(2., dtype=np.float32)) + assert repr(x) == "" def test_quantity_hash(self): x = self.Q_(4.2, "meter")