MCPcopy Create free account
hub / github.com/apache/arrow / test_project

Function test_project

python/pyarrow/tests/test_acero.py:137–166  ·  view source on GitHub ↗
(table_source)

Source from the content-addressed store, hash-verified

135
136
137def 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
169def test_aggregate_scalar(table_source):

Callers

nothing calls this directly

Calls 4

DeclarationClass · 0.90
fieldFunction · 0.90
to_tableMethod · 0.45
sumMethod · 0.45

Tested by

no test coverage detected