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

Function test_aggregate_hash

python/pyarrow/tests/test_acero.py:311–354  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

309
310
311def test_aggregate_hash():
312 table = pa.table({'a': [1, 2, None], 'b': ["foo", "bar", "foo"]})
313 table_opts = TableSourceNodeOptions(table)
314 table_source = Declaration("table_source", options=table_opts)
315
316 # default options
317 aggr_opts = AggregateNodeOptions(
318 [("a", "hash_count", None, "count(a)")], keys=["b"])
319 decl = Declaration.from_sequence([
320 table_source, Declaration("aggregate", aggr_opts)
321 ])
322 result = decl.to_table()
323 expected = pa.table({"b": ["foo", "bar"], "count(a)": [1, 1]})
324 assert result.equals(expected)
325
326 # specify function options
327 aggr_opts = AggregateNodeOptions(
328 [("a", "hash_count", pc.CountOptions("all"), "count(a)")], keys=["b"]
329 )
330 decl = Declaration.from_sequence([
331 table_source, Declaration("aggregate", aggr_opts)
332 ])
333 result = decl.to_table()
334 expected_all = pa.table({"b": ["foo", "bar"], "count(a)": [2, 1]})
335 assert result.equals(expected_all)
336
337 # specify keys as field references
338 aggr_opts = AggregateNodeOptions(
339 [("a", "hash_count", None, "count(a)")], keys=[field("b")]
340 )
341 decl = Declaration.from_sequence([
342 table_source, Declaration("aggregate", aggr_opts)
343 ])
344 result = decl.to_table()
345 assert result.equals(expected)
346
347 # wrong type of (aggregation) function
348 # TODO test with kernel that matches number of arguments (arity) -> avoid segfault
349 aggr_opts = AggregateNodeOptions([("a", "sum", None, "a_sum")], keys=["b"])
350 decl = Declaration.from_sequence([
351 table_source, Declaration("aggregate", aggr_opts)
352 ])
353 with pytest.raises(ValueError):
354 _ = decl.to_table()
355
356
357def test_order_by():

Callers

nothing calls this directly

Calls 7

TableSourceNodeOptionsFunction · 0.90
DeclarationClass · 0.90
fieldFunction · 0.90
equalsMethod · 0.80
CountOptionsMethod · 0.80
to_tableMethod · 0.45

Tested by

no test coverage detected