Skip to content

Commit f32d779

Browse files
redo
1 parent b40a9c7 commit f32d779

2 files changed

Lines changed: 5 additions & 5 deletions

File tree

tunits/core/cython/with_unit.pyx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -669,6 +669,11 @@ cdef class WithUnit:
669669
def sign(self) -> int | np.ndarray:
670670
return np.sign(self.value_in_base_units())
671671

672+
def dimensionless(self) -> float | np.ndarray:
673+
if not self._is_dimensionless():
674+
raise ValueError(f'{self} is not dimensionless')
675+
return self.value_in_base_units()
676+
672677
_try_interpret_as_with_unit = None
673678
_is_value_consistent_with_default_unit_database = None
674679
def init_base_unit_functions(

tunits/core/cython/with_unit_value.pyx

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
# limitations under the License.
1414

1515
from typing import TypeVar
16-
imag numbers
1716
import numpy as np
1817

1918
T = TypeVar('Value', bound='Value')
@@ -22,10 +21,6 @@ T = TypeVar('Value', bound='Value')
2221
class Value(WithUnit):
2322
"""A floating-point value with associated units."""
2423

25-
def __init__(self, value, unit):
26-
assert isinstance(value, numbers.Number)
27-
super().__init__(value, unit)
28-
2924
@classmethod
3025
def from_proto(cls: type[T], msg: 'tunits_pb2.Value') -> T:
3126
if msg.HasField('real_value'):

0 commit comments

Comments
 (0)