@@ -199,7 +199,6 @@ class SiDerivedUnit:
199199 ##############################################
200200
201201 def __init__ (self , string = None , powers = None ):
202-
203202 if powers is not None :
204203 self ._powers = self .new_powers ()
205204 self ._powers .update (powers )
@@ -393,7 +392,6 @@ def __new__(meta, class_name, base_classes, attributes):
393392
394393 @classmethod
395394 def init_unit (meta , cls ):
396-
397395 si_unit = cls .SI_UNIT
398396 if not (isinstance (si_unit , SiDerivedUnit ) and si_unit ):
399397 # si_unit is not defined
@@ -407,10 +405,8 @@ def init_unit(meta, cls):
407405
408406 @classmethod
409407 def register_unit (meta , cls ):
410-
411408 obj = cls ()
412409 meta ._units [obj .unit_suffix ] = obj
413-
414410 if obj .si_unit :
415411 hash_ = obj .si_unit .hash
416412 if hash_ in meta ._hash_map :
@@ -440,13 +436,11 @@ def from_hash(meta, hash_):
440436
441437 @classmethod
442438 def from_si_unit (meta , si_unit , unique = True ):
443-
444439 # Fixme:
445440 # - handle power of units
446441 # unit -> numpy vector, divide and test for identical factor
447442 # define unit, format as V^2
448443 # - complex unit
449-
450444 units = meta ._hash_map .get (si_unit .hash , None )
451445 if unique and units is not None :
452446 if len (units ) > 1 :
@@ -484,11 +478,9 @@ class Unit(metaclass=UnitMetaclass):
484478 ##############################################
485479
486480 def __init__ (self , si_unit = None ):
487-
488481 self ._unit_name = self .UNIT_NAME
489482 self ._unit_suffix = self .UNIT_SUFFIX
490483 self ._quantity = self .QUANTITY
491-
492484 if si_unit is None :
493485 self ._si_unit = self .SI_UNIT
494486 else :
@@ -559,7 +551,6 @@ def _equivalent_prefixed_unit(self, si_unit):
559551 ##############################################
560552
561553 def _equivalent_unit (self , si_unit ):
562-
563554 equivalent_unit = UnitMetaclass .from_si_unit (si_unit )
564555 if equivalent_unit is not None :
565556 return equivalent_unit
@@ -705,7 +696,6 @@ def from_si_unit(cls, si_unit):
705696
706697 @classmethod
707698 def from_prefixed_unit (cls , unit , power = 0 ):
708-
709699 if unit .unit_suffix :
710700 unit_key = str (unit )
711701 else :
@@ -720,7 +710,6 @@ def from_prefixed_unit(cls, unit, power=0):
720710 ##############################################
721711
722712 def __init__ (self , unit = None , power = None , value_ctor = None , values_ctor = None ):
723-
724713 if unit is None :
725714 self ._unit = Unit ()
726715 else :
@@ -816,10 +805,8 @@ def str(self, spice=False, unit=True):
816805 # Fixme: unit clash, e.g. mm ???
817806
818807 string = self ._power .str (spice )
819-
820808 if unit :
821809 string += str (self ._unit )
822-
823810 if spice :
824811 # F is interpreted as f = femto
825812 if string == 'F' :
@@ -832,7 +819,6 @@ def str(self, spice=False, unit=True):
832819 # U+2109 ℉
833820 string = string .replace ('Ω' , 'Ohm' ) # U+CEA0
834821 string = string .replace ('μ' , 'u' ) # U+CEBC
835-
836822 return string
837823
838824 ##############################################
@@ -875,9 +861,7 @@ def simple_value(cls, value):
875861 ##############################################
876862
877863 def __init__ (self , prefixed_unit , value ):
878-
879864 self ._prefixed_unit = prefixed_unit
880-
881865 if isinstance (value , UnitValue ):
882866 # Fixme: anonymous ???
883867 if not self .is_same_unit (value ):
@@ -1129,9 +1113,7 @@ def __rmul__(self, other):
11291113 ##############################################
11301114
11311115 def __floordiv__ (self , other ):
1132-
11331116 """self // other """
1134-
11351117 if (isinstance (other , UnitValue )):
11361118 equivalent_unit = self .unit .divide (other .unit , True )
11371119 value = float (self ) // float (other )
@@ -1167,9 +1149,7 @@ def __rfloordiv__(self, other):
11671149 ##############################################
11681150
11691151 def __truediv__ (self , other ):
1170-
11711152 """self / other"""
1172-
11731153 if (isinstance (other , UnitValue )):
11741154 equivalent_unit = self .unit .divide (other .unit , True )
11751155 value = float (self ) / float (other )
@@ -1345,9 +1325,7 @@ def convert_to_power(self, power=0):
13451325 ##############################################
13461326
13471327 def canonise (self ):
1348-
13491328 # log10(10**n) = n log10(1) = 0 log10(10**-n) = -n log10(0) = -oo
1350-
13511329 try :
13521330 abs_value = abs (float (self ))
13531331 log = math .log (abs_value )/ math .log (1000 )
@@ -1507,18 +1485,15 @@ class UnitValues(np.ndarray):
15071485
15081486 @classmethod
15091487 def from_ndarray (cls , array , prefixed_unit ):
1510-
15111488 # cls._logger.debug('UnitValues.__new__ ' + str((cls, array, prefixed_unit)))
15121489
15131490 # obj = cls(prefixed_unit, array.shape, array.dtype) # Fixme: buffer ???
15141491 # obj[...] = array[...]
15151492
15161493 obj = array .view (UnitValues )
15171494 obj ._prefixed_unit = prefixed_unit
1518-
15191495 if isinstance (array , UnitValues ):
15201496 return array .convert (prefixed_unit )
1521-
15221497 return obj
15231498
15241499 ##############################################
@@ -1534,9 +1509,7 @@ def __new__(cls,
15341509
15351510 obj = super (UnitValues , cls ).__new__ (cls , shape , dtype , buffer , offset , strides , order )
15361511 # obj = np.asarray(input_array).view(cls)
1537-
15381512 obj ._prefixed_unit = prefixed_unit
1539-
15401513 return obj
15411514
15421515 ##############################################
@@ -1724,9 +1697,7 @@ def __array_ufunc__(self, ufunc, method, *inputs, **kwargs):
17241697 ##############################################
17251698
17261699# def __array_wrap__(self, out_array, context=None):
1727- #
17281700# self._logger.debug('\n self={}\n out_array={}\n context={}'.format(self, out_array, context))
1729- #
17301701# return super(UnitValues, self).__array_wrap__(out_array, context)
17311702
17321703 ##############################################
@@ -1741,9 +1712,7 @@ def as_ndarray(self, scale=False):
17411712 ##############################################
17421713
17431714 def __getitem__ (self , slice_ ):
1744-
17451715 value = super (UnitValues , self ).__getitem__ (slice_ )
1746-
17471716 if isinstance (value , UnitValue ): # slice
17481717 return value
17491718 else :
@@ -1752,14 +1721,12 @@ def __getitem__(self, slice_):
17521721 ##############################################
17531722
17541723 def __setitem__ (self , slice_ , value ):
1755-
17561724 if isinstance (value , UnitValue ):
17571725 self ._check_unit (value )
17581726 value = self ._convert_value (value ).value
17591727 elif isinstance (value , UnitValues ):
17601728 self ._check_unit (value )
17611729 value = self ._convert_value (value )
1762-
17631730 super (UnitValues , self ).__setitem__ (slice_ , value )
17641731
17651732 ##############################################
0 commit comments