From 21ff2b813ffaf4b8640fe3254841503ea2dcaaec Mon Sep 17 00:00:00 2001
From: studga00 <gabriel.studer@stud.unibas.ch>
Date: Mon, 13 Aug 2012 11:45:14 +0200
Subject: [PATCH] do not allow to add a column with a name, that already exists

---
 modules/base/pymod/table.py      | 4 ++++
 modules/base/tests/test_table.py | 4 ++++
 2 files changed, 8 insertions(+)

diff --git a/modules/base/pymod/table.py b/modules/base/pymod/table.py
index 5a08b90eb..3bd8c750e 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 b4242473e..7337dfbe6 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
-- 
GitLab