diff --git a/modules/base/pymod/table.py b/modules/base/pymod/table.py index 5a08b90ebe6502ae49bddd5d60dd7bdb72112e58..3bd8c750e8bb7653cf693e8815673f8bd3674687 100644 --- a/modules/base/pymod/table.py +++ b/modules/base/pymod/table.py @@ -695,6 +695,10 @@ Statistics for column %(col)s As a special case, if there are no previous rows, and data is not None, rows are added for every item in data. """ + + if col_name in self.col_names: + raise ValueError('Column with name %s already exists'%col_name) + col_type = self._ParseColTypes(col_type, exp_num=1)[0] self.col_names.append(col_name) self.col_types.append(col_type) diff --git a/modules/base/tests/test_table.py b/modules/base/tests/test_table.py index b4242473e344f132eaa74f0164f7b16902a11335..7337dfbe63baf40cb74e85de3448887ecff020db 100644 --- a/modules/base/tests/test_table.py +++ b/modules/base/tests/test_table.py @@ -604,6 +604,10 @@ class TestTable(unittest.TestCase): tab.AddCol('a','f',[4.2,4.2,4.2]) self.assertRaises(ValueError, tab.AddCol, 'b', 'f', [4.2,4.2]) + def testRaiseErrorColNameAlreadyExists(self): + tab = Table() + tab.AddCol('awesome','f') + self.assertRaises(ValueError, tab.AddCol, 'awesome', 'f') def testRaiseErrorOnWrongColumnTypes(self): # wrong columns types in init