From c1cf2eaa155eae0928c26b74136a94f087030782 Mon Sep 17 00:00:00 2001 From: Derin Date: Thu, 11 Dec 2025 20:35:08 +0530 Subject: [PATCH] Add tests for Table.apply error handling (#476) --- tests/test_table_apply_errors.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 tests/test_table_apply_errors.py diff --git a/tests/test_table_apply_errors.py b/tests/test_table_apply_errors.py new file mode 100644 index 00000000..55164fb2 --- /dev/null +++ b/tests/test_table_apply_errors.py @@ -0,0 +1,21 @@ +import pytest +from datascience import Table + +def test_apply_non_callable(): + table = Table().with_columns("numbers", [1, 2, 3]) + with pytest.raises(TypeError): + table.apply(123, "numbers") + +def test_apply_invalid_column_name(): + table = Table().with_columns("numbers", [1, 2, 3]) + with pytest.raises(ValueError): + table.apply(lambda x: x, "non_existent_column") + +def test_apply_function_returns_invalid_type(): + table = Table().with_columns("numbers", [1, 2, 3]) + + def bad_fn(x): + return list(range(x)) + with pytest.raises(Exception): + table.apply(bad_fn, "numbers") +