@@ -199,7 +199,7 @@ cdef class WithUnit:
199199 if unit_val is None :
200200 raise ValueError (" Bad WithUnit scaling value: " + repr (value))
201201
202- if isinstance (value, (int , float , np.ndarray)):
202+ if isinstance (value, (numbers.Number , np.ndarray)):
203203 self .value = unit_val.value * value
204204 self .conv = unit_val.conv
205205 self .base_units = unit_val.base_units
@@ -259,7 +259,7 @@ cdef class WithUnit:
259259 def __mul__ (left , b ) -> 'WithUnit':
260260 cdef WithUnit right
261261 try:
262- if isinstance(b , ( int , float ) ):
262+ if isinstance(b , numbers. Number ):
263263 return left.__with_value(left.value * b)
264264 right = _in_WithUnit(b)
265265 if left._is_dimensionless() and right._is_dimensionless():
@@ -279,7 +279,7 @@ cdef class WithUnit:
279279 return NotImplemented
280280 def __rmul__ (self , b ):
281281 try :
282- if isinstance (b, ( int , float ) ):
282+ if isinstance (b, numbers.Number ):
283283 return self .__with_value(self .value * b)
284284 return self * b
285285 except NotTUnitsLikeError:
@@ -288,7 +288,7 @@ cdef class WithUnit:
288288 def __truediv__ (a , b ):
289289 cdef WithUnit left, right
290290 try :
291- if isinstance (b, ( int , float ) ):
291+ if isinstance (b, numbers.Number ):
292292 return a.__with_value(a.value / b)
293293 left = _in_WithUnit(a)
294294 right = _in_WithUnit(b)
@@ -322,7 +322,7 @@ cdef class WithUnit:
322322 cdef WithUnit left, right
323323 cdef double c
324324 try :
325- if isinstance (b, ( int , float ) ):
325+ if isinstance (b, numbers.Number ):
326326 return a.value// b, _in_WithUnit(a.value % b)
327327 left = _in_WithUnit(a)
328328 right = _in_WithUnit(b)
@@ -388,12 +388,6 @@ cdef class WithUnit:
388388 def imag (WithUnit self ):
389389 return self .__with_value(self .value.imag)
390390
391- # def round(WithUnit self, unit):
392- # try:
393- # return self.in_units_of(unit, True)
394- # except NotTUnitsLikeError:
395- # return NotImplemented
396-
397391 def __int__ (self ):
398392 if self .base_units.unit_count != 0 :
399393 raise UnitMismatchError(
@@ -673,22 +667,6 @@ cdef class WithUnit:
673667 def conjugate(self ) -> 'WithUnit':
674668 return self.__with_value(self.value.conjugate())
675669
676- # def floor(self , u ):
677- # cdef WithUnit converted
678- # try:
679- # converted = self.in_units_of(u, False)
680- # return converted.__with_value(floor(converted.value))
681- # except NotTUnitsLikeError:
682- # return NotImplemented
683-
684- # def ceil(self, u):
685- # cdef WithUnit converted
686- # try:
687- # converted = self.in_units_of(u, False)
688- # return converted.__with_value(ceil(converted.value))
689- # except NotTUnitsLikeError:
690- # return NotImplemented
691-
692670 def sign(self ) -> int | np.ndarray:
693671 return np.sign(self.value_in_base_units())
694672
0 commit comments