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

Function test_project

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

Source from the content-addressed store, hash-verified

226
227
228def 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
260def 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