(table_source)
| 135 | |
| 136 | |
| 137 | def test_project(table_source): |
| 138 | # default name from expression |
| 139 | decl = Declaration.from_sequence([ |
| 140 | table_source, |
| 141 | Declaration("project", ProjectNodeOptions([pc.multiply(field("a"), 2)])) |
| 142 | ]) |
| 143 | result = decl.to_table() |
| 144 | assert result.schema.names == ["multiply(a, 2)"] |
| 145 | assert result[0].to_pylist() == [2, 4, 6] |
| 146 | |
| 147 | # provide name |
| 148 | decl = Declaration.from_sequence([ |
| 149 | table_source, |
| 150 | Declaration("project", ProjectNodeOptions([pc.multiply(field("a"), 2)], ["a2"])) |
| 151 | ]) |
| 152 | result = decl.to_table() |
| 153 | assert result.schema.names == ["a2"] |
| 154 | assert result["a2"].to_pylist() == [2, 4, 6] |
| 155 | |
| 156 | # input validation |
| 157 | with pytest.raises(ValueError): |
| 158 | ProjectNodeOptions([pc.multiply(field("a"), 2)], ["a2", "b2"]) |
| 159 | |
| 160 | # no scalar expression |
| 161 | decl = Declaration.from_sequence([ |
| 162 | table_source, |
| 163 | Declaration("project", ProjectNodeOptions([pc.sum(field("a"))])) |
| 164 | ]) |
| 165 | with pytest.raises(ValueError, match="cannot Execute non-scalar expression"): |
| 166 | _ = decl.to_table() |
| 167 | |
| 168 | |
| 169 | def test_aggregate_scalar(table_source): |
nothing calls this directly
no test coverage detected