Skip to content
Snippets Groups Projects
Commit 32b03c0c authored by Gabriel Studer's avatar Gabriel Studer
Browse files

force user to provide data with same length as number of rows in the table

when adding a new column
parent 21c3de10
No related branches found
No related tags found
No related merge requests found
......@@ -654,6 +654,11 @@ class Table(object):
for row in self.rows:
row.append(data)
else:
if len(data)!=len(self.rows):
self.col_names.pop()
self.col_types.pop()
raise ValueError('Length of data (%i) must correspond to number of '%len(data) +\
'existing rows (%i)'%len(self.rows))
for row, d in zip(self.rows, data):
row.append(d)
......
......@@ -592,6 +592,11 @@ class TestTable(unittest.TestCase):
'foo': [True, None, True],
'bar': [1, 2, 3]})
def testRaiseErrorOnWrongDataLengthAddCol(self):
tab = Table()
tab.AddCol('a','f',[4.2,4.2,4.2])
self.assertRaises(ValueError, tab.AddCol, 'b', 'f', [4.2,4.2])
def testRaiseErrorOnWrongColumnTypes(self):
# wrong columns types in init
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment