Skip to content

Commit c1cf2ea

Browse files
committed
Add tests for Table.apply error handling (#476)
1 parent 7af1472 commit c1cf2ea

1 file changed

Lines changed: 21 additions & 0 deletions

File tree

tests/test_table_apply_errors.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import pytest
2+
from datascience import Table
3+
4+
def test_apply_non_callable():
5+
table = Table().with_columns("numbers", [1, 2, 3])
6+
with pytest.raises(TypeError):
7+
table.apply(123, "numbers")
8+
9+
def test_apply_invalid_column_name():
10+
table = Table().with_columns("numbers", [1, 2, 3])
11+
with pytest.raises(ValueError):
12+
table.apply(lambda x: x, "non_existent_column")
13+
14+
def test_apply_function_returns_invalid_type():
15+
table = Table().with_columns("numbers", [1, 2, 3])
16+
17+
def bad_fn(x):
18+
return list(range(x))
19+
with pytest.raises(Exception):
20+
table.apply(bad_fn, "numbers")
21+

0 commit comments

Comments
 (0)