diff --git a/python/pyarrow/compute.py b/python/pyarrow/compute.py index 6e3bd7fcab3..c8d5a1014b5 100644 --- a/python/pyarrow/compute.py +++ b/python/pyarrow/compute.py @@ -244,6 +244,10 @@ def _make_global_functions(): for cpp_name in reg.list_functions(): name = rewrites.get(cpp_name, cpp_name) func = reg.get_function(cpp_name) + if func.kind == "hash_aggregate": + # Hash aggregate functions are not callable, + # so let's not expose them at module level. + continue assert name not in g, name g[cpp_name] = g[name] = _wrap_function(name, func) diff --git a/python/pyarrow/tests/test_compute.py b/python/pyarrow/tests/test_compute.py index 5185232fd9b..1e1fadc0c83 100644 --- a/python/pyarrow/tests/test_compute.py +++ b/python/pyarrow/tests/test_compute.py @@ -96,6 +96,14 @@ def test_exported_functions(): func(*args) +def test_hash_aggregate_not_exported(): + # Ensure we are not leaking hash aggregate functions + # which are not callable by themselves. + for func in exported_functions: + arrow_f = pc.get_function(func.__arrow_compute_function__["name"]) + assert arrow_f.kind != "hash_aggregate" + + def test_exported_option_classes(): classes = exported_option_classes assert len(classes) >= 10 @@ -241,7 +249,11 @@ def test_pickle_functions(): def test_pickle_global_functions(): # Pickle global wrappers (manual or automatic) of registered functions for name in pc.list_functions(): - func = getattr(pc, name) + try: + func = getattr(pc, name) + except AttributeError: + # hash_aggregate functions are not exported as callables. + continue reconstructed = pickle.loads(pickle.dumps(func)) assert reconstructed is func