Skip to content

Commit 9c935d4

Browse files
amol-pitrou
authored andcommitted
ARROW-13943: [Python] Hide hash_aggregate functions from compute module
Closes #11745 from amol-/ARROW-13943 Authored-by: Alessandro Molina <[email protected]> Signed-off-by: Antoine Pitrou <[email protected]>
1 parent 2155d46 commit 9c935d4

2 files changed

Lines changed: 17 additions & 1 deletion

File tree

‎python/pyarrow/compute.py‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,10 @@ def _make_global_functions():
254254
for cpp_name in reg.list_functions():
255255
name = rewrites.get(cpp_name, cpp_name)
256256
func = reg.get_function(cpp_name)
257+
if func.kind == "hash_aggregate":
258+
# Hash aggregate functions are not callable,
259+
# so let's not expose them at module level.
260+
continue
257261
assert name not in g, name
258262
g[cpp_name] = g[name] = _wrap_function(name, func)
259263

‎python/pyarrow/tests/test_compute.py‎

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,14 @@ def test_exported_functions():
9696
func(*args)
9797

9898

99+
def test_hash_aggregate_not_exported():
100+
# Ensure we are not leaking hash aggregate functions
101+
# which are not callable by themselves.
102+
for func in exported_functions:
103+
arrow_f = pc.get_function(func.__arrow_compute_function__["name"])
104+
assert arrow_f.kind != "hash_aggregate"
105+
106+
99107
def test_exported_option_classes():
100108
classes = exported_option_classes
101109
assert len(classes) >= 10
@@ -241,7 +249,11 @@ def test_pickle_functions():
241249
def test_pickle_global_functions():
242250
# Pickle global wrappers (manual or automatic) of registered functions
243251
for name in pc.list_functions():
244-
func = getattr(pc, name)
252+
try:
253+
func = getattr(pc, name)
254+
except AttributeError:
255+
# hash_aggregate functions are not exported as callables.
256+
continue
245257
reconstructed = pickle.loads(pickle.dumps(func))
246258
assert reconstructed is func
247259

0 commit comments

Comments
 (0)