Skip to content

Commit

Permalink
check arguments for Table.append to only accept row with the same amo…
Browse files Browse the repository at this point in the history
…unt of elements as columns of the table
  • Loading branch information
adnanhemani committed Jan 13, 2017
1 parent 7c6a05c commit 9849c2a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
2 changes: 2 additions & 0 deletions datascience/tables.py
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,8 @@ def append(self, row_or_table):
columns = list(t.select(self.labels)._columns.values())
n = t.num_rows
else:
if (len(row_or_table) != self.num_columns):
raise Exception('Row should have '+ str(self.num_columns) + " columns")
columns, n = [[value] for value in row_or_table], 1
for i, column in enumerate(self._columns):
if self.num_rows:
Expand Down
12 changes: 12 additions & 0 deletions tests/test_tables.py
Original file line number Diff line number Diff line change
Expand Up @@ -530,6 +530,18 @@ def test_append_row(table):
g | 2 | 2
""")


def test_append_row_different_num_cols(table):
"""Makes sure that any incoming row must have the same amount of columns as the table."""
row = "abcd"
with(pytest.raises(Exception)):
table.append(row)

row = ["e", 2, 4, 6]
with(pytest.raises(Exception)):
table.append(row)


def test_append_column(table):
column_1 = [10, 20, 30, 40]
column_2 = 'hello'
Expand Down

0 comments on commit 9849c2a

Please sign in to comment.