@@ -183,13 +183,15 @@ def __getitem__(self, item):  # pragma: no cover
183183                if  variable  in  key_string :
184184                    found_variable  =  True 
185185                    break 
186-             assert  found_variable , "Input string {} is not a key of the data dictionary." .format (variable )
186+             if  not  found_variable :
187+                 raise  KeyError (f"Input string { variable }   is not a key of the data dictionary." )
187188            data_out ._data [variable ] =  self ._data [key_string ]
188189            data_out ._header .append (variable )
189190        return  data_out 
190191
191192    def  __add__ (self , other ):  # pragma: no cover 
192-         assert  self .number_of_columns  ==  other .number_of_columns , "Inconsistent number of columns" 
193+         if  self .number_of_columns  !=  other .number_of_columns :
194+             raise  ValueError ("Number of columns is inconsistent." )
193195        # Create a new object to return, avoiding changing the original inputs 
194196        new_dataset  =  CSVDataset ()
195197        # Add empty columns to new_dataset 
@@ -224,7 +226,8 @@ def __iadd__(self, other):  # pragma: no cover
224226            for  column  in  other .data :
225227                self ._data [column ] =  []
226228
227-         assert  self .number_of_columns  ==  other .number_of_columns , "Inconsistent number of columns" 
229+         if  self .number_of_columns  !=  other .number_of_columns :
230+             raise  ValueError ("Number of columns is inconsistent." )
228231
229232        # Append the data from 'other' 
230233        for  column , row_data  in  other .data .items ():
@@ -1348,9 +1351,10 @@ def __init__(
13481351            self ._value  =  self ._calculated_value 
13491352        # If units have been specified, check for a conflict and otherwise use the specified unit system 
13501353        if  units :
1351-             assert  not  self ._units , "The unit specification {} is inconsistent with the identified units {}." .format (
1352-                 specified_units , self ._units 
1353-             )
1354+             if  self ._units  and  self ._units  !=  specified_units :
1355+                 raise  RuntimeError (
1356+                     f"The unit specification { specified_units }   is inconsistent with the identified units { self ._units }  ." 
1357+                 )
13541358            self ._units  =  specified_units 
13551359
13561360        if  not  si_value  and  is_number (self ._value ):
@@ -1737,9 +1741,10 @@ def rescale_to(self, units):  # pragma: no cover
17371741
17381742        """ 
17391743        new_unit_system  =  unit_system (units )
1740-         assert  new_unit_system  ==  self .unit_system , (
1741-             "New unit system {0} is inconsistent with the current unit system {1}." 
1742-         )
1744+         if  new_unit_system  !=  self .unit_system :
1745+             raise  ValueError (
1746+                 f"New unit system { new_unit_system }   is inconsistent with the current unit system { self .unit_system }  ." 
1747+             )
17431748        self ._units  =  units 
17441749        return  self 
17451750
@@ -1810,7 +1815,8 @@ def __mul__(self, other):  # pragma: no cover
18101815        >>> assert result_3.unit_system == "Power" 
18111816
18121817        """ 
1813-         assert  is_number (other ) or  isinstance (other , Variable ), "Multiplier must be a scalar quantity or a variable." 
1818+         if  not  is_number (other ) and  not  isinstance (other , Variable ):
1819+             raise  ValueError ("Multiplier must be a scalar quantity or a variable." )
18141820        if  is_number (other ):
18151821            result_value  =  self .numeric_value  *  other 
18161822            result_units  =  self .units 
@@ -1854,10 +1860,10 @@ def __add__(self, other):  # pragma: no cover
18541860        >>> assert result.unit_system == "Current" 
18551861
18561862        """ 
1857-         assert   isinstance (other , Variable ),  "You can only add a variable with another variable." 
1858-         assert   self . unit_system   ==   other . unit_system , ( 
1859-              "Only ``Variable`` objects with the same unit system can be added." 
1860-         )
1863+         if   not   isinstance (other , Variable ): 
1864+              raise   ValueError ( "You can only add a variable with another variable." ) 
1865+         if   self . unit_system   !=   other . unit_system : 
1866+              raise   ValueError ( "Only Variable objects with the same unit system can be added." )
18611867        result_value  =  self .value  +  other .value 
18621868        result_units  =  SI_UNITS [self .unit_system ]
18631869        # If the units of the two operands are different, return SI-Units 
@@ -1895,10 +1901,10 @@ def __sub__(self, other):  # pragma: no cover
18951901        >>> assert result_2.unit_system == "Current" 
18961902
18971903        """ 
1898-         assert   isinstance (other , Variable ),  "You can only subtract a variable from another variable." 
1899-         assert   self . unit_system   ==   other . unit_system , ( 
1900-              "Only ``Variable`` objects with the same unit system can be subtracted." 
1901-         )
1904+         if   not   isinstance (other , Variable ): 
1905+              raise   ValueError ( "You can only subtract a variable from another variable." ) 
1906+         if   self . unit_system   !=   other . unit_system : 
1907+              raise   ValueError ( "Only Variable objects with the same unit system can be subtracted." )
19021908        result_value  =  self .value  -  other .value 
19031909        result_units  =  SI_UNITS [self .unit_system ]
19041910        # If the units of the two operands are different, return SI-Units 
@@ -1940,7 +1946,8 @@ def __truediv__(self, other):  # pragma: no cover
19401946        >>> assert result_1.unit_system == "Current" 
19411947
19421948        """ 
1943-         assert  is_number (other ) or  isinstance (other , Variable ), "Divisor must be a scalar quantity or a variable." 
1949+         if  not  is_number (other ) and  not  isinstance (other , Variable ):
1950+             raise  ValueError ("Divisor must be a scalar quantity or a variable." )
19441951        if  is_number (other ):
19451952            result_value  =  self .numeric_value  /  other 
19461953            result_units  =  self .units 
0 commit comments