diff --git a/CHANGES b/CHANGES index 11df3542b..10839cddc 100644 --- a/CHANGES +++ b/CHANGES @@ -8,6 +8,7 @@ Pint Changelog - Support python 3.9 following difficulties installing with NumPy 2. (PR #2019) - Fix default formatting of dimensionless unit issue. (PR #2012) - Fix bug preventing custom formatters with modifiers working. (PR #2021) +- Change Quantity repr to include magnitude repr & units. 0.24 (2024-06-07) ----------------- diff --git a/pint/facets/plain/quantity.py b/pint/facets/plain/quantity.py index a18919273..7ae36d151 100644 --- a/pint/facets/plain/quantity.py +++ b/pint/facets/plain/quantity.py @@ -275,13 +275,13 @@ def __bytes__(self) -> bytes: def __repr__(self) -> str: if HAS_UNCERTAINTIES: if isinstance(self._magnitude, UFloat): - return f"" + return f"" else: - return f"" + return f"" elif isinstance(self._magnitude, float): - return f"" + return f"" - 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 8c6f15c49..969d61a19 100644 --- a/pint/testsuite/test_quantity.py +++ b/pint/testsuite/test_quantity.py @@ -126,7 +126,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.0)) + assert repr(x) == "" + x = self.Q_(np.array(2.0, dtype=np.float32)) + assert repr(x) == "" def test_quantity_hash(self): x = self.Q_(4.2, "meter")