Skip to content

Commit

Permalink
append_column now returns the table modified as well
Browse files Browse the repository at this point in the history
  • Loading branch information
adnanhemani committed May 16, 2017
1 parent 7a7ca82 commit d713ab3
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
3 changes: 1 addition & 2 deletions datascience/tables.py
Original file line number Diff line number Diff line change
Expand Up @@ -449,14 +449,12 @@ def append_column(self, label, values):
c | 3 | 2
z | 1 | 10
>>> table.append_column('new_col1', make_array(10, 20, 30, 40))
>>> table
letter | count | points | new_col1
a | 9 | 1 | 10
b | 3 | 2 | 20
c | 3 | 2 | 30
z | 1 | 10 | 40
>>> table.append_column('new_col2', 'hello')
>>> table
letter | count | points | new_col1 | new_col2
a | 9 | 1 | 10 | hello
b | 3 | 2 | 20 | hello
Expand Down Expand Up @@ -491,6 +489,7 @@ def append_column(self, label, values):
self._num_rows = len(values)

self._columns[label] = values
return self

def relabel(self, column_label, new_label):
"""Changes the label(s) of column(s) specified by ``column_label`` to
Expand Down
10 changes: 8 additions & 2 deletions tests/test_tables.py
Original file line number Diff line number Diff line change
Expand Up @@ -585,15 +585,21 @@ def test_append_column(table):
c | 3 | 2 | 30
z | 1 | 10 | 40
""")
table.append_column('new_col2', column_2)
print(table)
ret_table = table.append_column('new_col2', column_2)
assert_equal(table, """
letter | count | points | new_col1 | new_col2
a | 9 | 1 | 10 | hello
b | 3 | 2 | 20 | hello
c | 3 | 2 | 30 | hello
z | 1 | 10 | 40 | hello
""")
assert_equal(ret_table, """
letter | count | points | new_col1 | new_col2
a | 9 | 1 | 10 | hello
b | 3 | 2 | 20 | hello
c | 3 | 2 | 30 | hello
z | 1 | 10 | 40 | hello
""")

with(pytest.raises(ValueError)):
table.append_column('bad_col', [1, 2])
Expand Down

0 comments on commit d713ab3

Please sign in to comment.