From 98b7ae3c417e019ca6c1c6ac5dcf659652aca723 Mon Sep 17 00:00:00 2001 From: Philipp Rehner Date: Tue, 28 Apr 2026 20:37:09 +0200 Subject: [PATCH] Fix the String representation of non-scalar mass quantities --- si-units/CHANGELOG.md | 3 +++ si-units/src/lib.rs | 9 ++++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/si-units/CHANGELOG.md b/si-units/CHANGELOG.md index a292864..def096c 100644 --- a/si-units/CHANGELOG.md +++ b/si-units/CHANGELOG.md @@ -8,6 +8,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed - Generalized indexing, such that, e.g., general multidimensional slicing operations are possible for quantities containing NumPy arrays. [#110](https://github.com/itt-ustutt/quantity/pull/110) +### Fixed +- Fixed the String representation of non-scalar mass quantities. [#111](https://github.com/itt-ustutt/quantity/pull/111) + ## [0.11.3] - 2026-04-22 ### Added - Added stub information for methods and constants. [#106](https://github.com/itt-ustutt/quantity/pull/106) diff --git a/si-units/src/lib.rs b/si-units/src/lib.rs index bb0b8a5..335de7e 100644 --- a/si-units/src/lib.rs +++ b/si-units/src/lib.rs @@ -83,7 +83,14 @@ impl PySIObject { .value .call_method0(py, "__repr__")? .extract::(py)?; - Ok(format!("{} {}", value, self.unit)) + let unit = if self.unit == _KILOGRAM { + // because the base unit already has a prefix, we cannot call + // unit.to_string() on it (it would return 'g'). + "kg".into() + } else { + self.unit.to_string() + }; + Ok(format!("{} {}", value, unit)) } }