|
6 | 6 | from numpy._typing import ArrayLike |
7 | 7 |
|
8 | 8 | from sasdata.quantities import units |
| 9 | +from sasdata.quantities.unit_parser import parse_unit |
9 | 10 | from sasdata.quantities.numerical_encoding import numerical_decode, numerical_encode |
10 | 11 | from sasdata.quantities.units import NamedUnit, Unit |
11 | 12 |
|
@@ -1180,6 +1181,16 @@ def in_si_with_standard_error(self): |
1180 | 1181 | else: |
1181 | 1182 | return self.in_si(), None |
1182 | 1183 |
|
| 1184 | + def explicitly_formatted(self, unit_string: str) -> str: |
| 1185 | + """Returns quantity as a string with specific unit formatting |
| 1186 | +
|
| 1187 | + Performs any necessary unit conversions, but maintains the exact unit |
| 1188 | + formatting provided by the user. This can be useful if you have a |
| 1189 | + power expressed in horsepower and you want it expressed as "745.7 N m/s" and not as "745.7 W". """ |
| 1190 | + unit = parse_unit(unit_string) |
| 1191 | + quantity = self.in_units_of(unit) |
| 1192 | + return f"{quantity} {unit_string}" |
| 1193 | + |
1183 | 1194 | def __eq__(self: Self, other: Self) -> bool | np.ndarray: |
1184 | 1195 | return self.value == other.in_units_of(self.units) |
1185 | 1196 |
|
@@ -1337,6 +1348,7 @@ def __pow__(self: Self, other: int | float): |
1337 | 1348 |
|
1338 | 1349 | @staticmethod |
1339 | 1350 | def _array_repr_format(arr: np.ndarray): |
| 1351 | + |
1340 | 1352 | """ Format the array """ |
1341 | 1353 | order = len(arr.shape) |
1342 | 1354 | reshaped = arr.reshape(-1) |
|
0 commit comments