From 58985b45ab79ef7c487681f7762e592c5148e544 Mon Sep 17 00:00:00 2001 From: Alessandro Molina Date: Fri, 19 Nov 2021 16:01:42 +0100 Subject: [PATCH 1/2] Hide hash_aggregate functions from compute module --- python/pyarrow/compute.py | 4 ++++ python/pyarrow/tests/test_compute.py | 7 +++++++ 2 files changed, 11 insertions(+) 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..f2074b039de 100644 --- a/python/pyarrow/tests/test_compute.py +++ b/python/pyarrow/tests/test_compute.py @@ -96,6 +96,13 @@ 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: + assert func.kind != "hash_aggregate" + + def test_exported_option_classes(): classes = exported_option_classes assert len(classes) >= 10 From 087e189f0179679fd1592e50ad9116b4fa02bf87 Mon Sep 17 00:00:00 2001 From: Alessandro Molina Date: Fri, 19 Nov 2021 16:51:43 +0100 Subject: [PATCH 2/2] fix tests --- python/pyarrow/tests/test_compute.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/python/pyarrow/tests/test_compute.py b/python/pyarrow/tests/test_compute.py index f2074b039de..1e1fadc0c83 100644 --- a/python/pyarrow/tests/test_compute.py +++ b/python/pyarrow/tests/test_compute.py @@ -100,7 +100,8 @@ 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: - assert func.kind != "hash_aggregate" + arrow_f = pc.get_function(func.__arrow_compute_function__["name"]) + assert arrow_f.kind != "hash_aggregate" def test_exported_option_classes(): @@ -248,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