(table_source)
| 226 | |
| 227 | |
| 228 | def test_project(table_source): |
| 229 | # default name from expression |
| 230 | decl = Declaration.from_sequence([ |
| 231 | table_source, |
| 232 | Declaration("project", ProjectNodeOptions([pc.multiply(field("a"), 2)])) |
| 233 | ]) |
| 234 | result = decl.to_table() |
| 235 | assert result.schema.names == ["multiply(a, 2)"] |
| 236 | assert result[0].to_pylist() == [2, 4, 6] |
| 237 | |
| 238 | # provide name |
| 239 | decl = Declaration.from_sequence([ |
| 240 | table_source, |
| 241 | Declaration("project", ProjectNodeOptions([pc.multiply(field("a"), 2)], ["a2"])) |
| 242 | ]) |
| 243 | result = decl.to_table() |
| 244 | assert result.schema.names == ["a2"] |
| 245 | assert result["a2"].to_pylist() == [2, 4, 6] |
| 246 | |
| 247 | # input validation |
| 248 | with pytest.raises(ValueError): |
| 249 | ProjectNodeOptions([pc.multiply(field("a"), 2)], ["a2", "b2"]) |
| 250 | |
| 251 | # no scalar expression |
| 252 | decl = Declaration.from_sequence([ |
| 253 | table_source, |
| 254 | Declaration("project", ProjectNodeOptions([pc.sum(field("a"))])) |
| 255 | ]) |
| 256 | with pytest.raises(ValueError, match="cannot Execute non-scalar expression"): |
| 257 | _ = decl.to_table() |
| 258 | |
| 259 | |
| 260 | def test_aggregate_scalar(table_source): |
nothing calls this directly
no test coverage detected