Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions python/pyarrow/_compute.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -2767,6 +2767,9 @@ def register_aggregate_function(func, function_name, function_doc, in_types, out
This is often used with ordered or segmented aggregation where groups
can be emit before accumulating all of the input data.

Note that currently the size of any input column can not exceed 2 GB
for a single segment (all groups combined).

Parameters
----------
func : callable
Expand Down Expand Up @@ -2823,6 +2826,15 @@ def register_aggregate_function(func, function_name, function_doc, in_types, out
>>> answer = pc.call_function(func_name, [pa.array([20, 40])])
>>> answer
<pyarrow.DoubleScalar: 30.0>
>>> table = pa.table([pa.array([1, 1, 2, 2]), pa.array([10, 20, 30, 40])], names=['k', 'v'])
>>> result = table.group_by('k').aggregate([('v', 'py_compute_median')])
>>> result
pyarrow.Table
k: int64
v_py_compute_median: double
----
k: [[1,2]]
v_py_compute_median: [[15,35]]
"""
return _register_user_defined_function(get_register_aggregate_function(),
func, function_name, function_doc, in_types,
Expand Down
10 changes: 5 additions & 5 deletions python/pyarrow/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
from pyarrow import Codec
from pyarrow import fs

import numpy as np

groups = [
'acero',
'brotli',
Expand Down Expand Up @@ -283,15 +285,14 @@ def unary_function(ctx, x):
@pytest.fixture(scope="session")
def unary_agg_func_fixture():
"""
Register a unary aggregate function
Register a unary aggregate function (mean)
"""
from pyarrow import compute as pc
import numpy as np

def func(ctx, x):
return pa.scalar(np.nanmean(x))

func_name = "y=avg(x)"
func_name = "mean_udf"
func_doc = {"summary": "y=avg(x)",
"description": "find mean of x"}

Expand All @@ -312,15 +313,14 @@ def varargs_agg_func_fixture():
Register a unary aggregate function
"""
from pyarrow import compute as pc
import numpy as np

def func(ctx, *args):
sum = 0.0
for arg in args:
sum += np.nanmean(arg)
return pa.scalar(sum)

func_name = "y=sum_mean(x...)"
func_name = "sum_mean"
func_doc = {"summary": "Varargs aggregate",
"description": "Varargs aggregate"}

Expand Down
Loading