We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
__format__
__str__
spec=''
2 parents a4e9267 + 6799c7f commit 91f907cCopy full SHA for 91f907c
2 files changed
test/test_value_array.py
@@ -263,3 +263,8 @@ class _InvalidUnit:
263
def test_invalid_unit_raises_error() -> None:
264
with pytest.raises(ValueError):
265
_ = tu.ValueArray([1, 2], _InvalidUnit())
266
+
267
268
+def test_format() -> None:
269
+ u = tu.GHz * np.random.random(10)
270
+ assert f'{u}' == str(u)
tunits/core/cython/with_unit.pyx
@@ -729,7 +729,7 @@ cdef class WithUnit:
729
self.base_units.__setstate__(pickle_info['base_units'])
730
731
def __format__(self, spec: str) -> str:
732
- if spec == '' and self.value == 1: return str(self)
+ if spec == '': return str(self)
733
return self.value.__format__(spec) + ' ' + str(self.unit)
734
735
_try_interpret_as_with_unit = None
0 commit comments