westonpace commented on code in PR #12590:
URL: https://github.com/apache/arrow/pull/12590#discussion_r856379848


##########
cpp/src/arrow/python/udf.cc:
##########
@@ -0,0 +1,132 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+#include "arrow/python/udf.h"
+
+#include <cstddef>
+#include <memory>
+#include <sstream>
+
+#include "arrow/compute/function.h"
+#include "arrow/python/common.h"
+
+namespace arrow {
+
+namespace py {
+
+Status CheckOutputType(const DataType& expected, const DataType& actual) {
+  if (!expected.Equals(actual)) {
+    return Status::TypeError("Expected output type, ", expected.name(),
+                             ", but function returned type ", actual.name());
+  }
+  return Status::OK();
+}
+
+struct PythonUdf {
+  ScalarUdfWrapperCallback cb;
+  std::shared_ptr<OwnedRefNoGIL> function;
+  compute::OutputType output_type;
+
+  // function needs to be destroyed at process exit
+  // and Python may no longer be initialized.
+  ~PythonUdf() {
+    if (_Py_IsFinalizing()) {
+      function->detach();
+    }
+  }
+
+  Status operator()(compute::KernelContext* ctx, const compute::ExecBatch& 
batch,
+                    Datum* out) {
+    return SafeCallIntoPython([=]() -> Status { return Execute(ctx, batch, 
out); });
+  }
+
+  Status Execute(compute::KernelContext* ctx, const compute::ExecBatch& batch,
+                 Datum* out) {
+    const auto num_args = batch.values.size();
+    ScalarUdfContext udf_context{ctx->memory_pool(), 
static_cast<int64_t>(num_args)};

Review Comment:
   ```suggestion
       ScalarUdfContext udf_context{ctx->memory_pool(), 
static_cast<int64_t>(batch.length)};
   ```



##########
python/pyarrow/tests/test_udf.py:
##########
@@ -0,0 +1,545 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+
+import pytest
+
+import pyarrow as pa
+from pyarrow import compute as pc
+
+
+# Marks all of the tests in this module
+# Ignore these with pytest ... -m 'not udf'
+# pytestmark = pytest.mark.udf
+
+unary_doc = {"summary": "add function",
+             "description": "test add function"}
+
+
[email protected](scope="session")
+def udf_context():
+    return pc._get_scalar_udf_context(pa.default_memory_pool(), 0)
+
+
[email protected](scope="session")
+def unary_func_fixture():
+    def unary_function(udf_context, scalar1):
+        return pc.call_function("add", [scalar1, 1])
+    return unary_function
+
+
+binary_doc = {"summary": "y=mx",
+              "description": "find y from y = mx"}
+
+
[email protected](scope="session")
+def binary_func_fixture():
+    def binary_function(ctx, m, x):
+        return pc.call_function("multiply", [m, x])
+    return binary_function
+
+
+ternary_doc = {"summary": "y=mx+c",
+               "description": "find y from y = mx + c"}
+
+
[email protected](scope="session")
+def ternary_func_fixture():
+    def ternary_function(ctx, m, x, c):
+        mx = pc.call_function("multiply", [m, x])
+        return pc.call_function("add", [mx, c])
+    return ternary_function
+
+
+varargs_doc = {"summary": "z=ax+by+c",
+               "description": "find z from z = ax + by + c"
+               }
+
+
[email protected](scope="session")
+def varargs_func_fixture():
+    def varargs_function(ctx, *values):
+        base_val = values[:2]
+        res = pc.call_function("add", base_val)
+        for other_val in values[2:]:
+            res = pc.call_function("add", [res, other_val])
+        return res
+    return varargs_function
+
+
[email protected](scope="session")
+def random_with_udf_ctx_func_fixture():
+    def random_with_udf_ctx(context, one, two):
+        old_pool = pa.default_memory_pool()
+        proxy_pool = pa.proxy_memory_pool(context.memory_pool)
+        pa.set_memory_pool(proxy_pool)
+        try:
+            ans = pc.add(one, two, memory_pool=proxy_pool)
+            allocated_before = proxy_pool.bytes_allocated()
+            # allocating 64 bytes
+            res = pa.array([ans.as_py()], memory_pool=proxy_pool)
+            allocated_after = proxy_pool.bytes_allocated()
+        finally:
+            pa.set_memory_pool(old_pool)
+        assert allocated_before == 0
+        assert allocated_after == 64

Review Comment:
   ```suggestion
           ans = pc.add(one, two, memory_pool=proxy_pool)
           res = pa.array([ans.as_py()], memory_pool=proxy_pool)
   ```
   
   There is no reason to change the default memory pool (and a real user 
shouldn't as that could be dangerous).  The important fact is that you are 
passing it to the call to `pc.add` and `pa.array`.  Also, checking bytes 
allocated here is just testing that `pc.add` is doing the right thing and that 
isn't very interesting (well, it might be interesting, but only for 
`test_compute.py`).  The C++ layer could be giving you the completely wrong 
memory pool and this check would still pass.



##########
python/pyarrow/tests/test_udf.py:
##########
@@ -0,0 +1,545 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+
+import pytest
+
+import pyarrow as pa
+from pyarrow import compute as pc
+
+
+# Marks all of the tests in this module
+# Ignore these with pytest ... -m 'not udf'
+# pytestmark = pytest.mark.udf
+
+unary_doc = {"summary": "add function",
+             "description": "test add function"}
+
+
[email protected](scope="session")
+def udf_context():
+    return pc._get_scalar_udf_context(pa.default_memory_pool(), 0)
+
+
[email protected](scope="session")
+def unary_func_fixture():
+    def unary_function(udf_context, scalar1):
+        return pc.call_function("add", [scalar1, 1])
+    return unary_function
+
+
+binary_doc = {"summary": "y=mx",
+              "description": "find y from y = mx"}
+
+
[email protected](scope="session")
+def binary_func_fixture():
+    def binary_function(ctx, m, x):
+        return pc.call_function("multiply", [m, x])
+    return binary_function
+
+
+ternary_doc = {"summary": "y=mx+c",
+               "description": "find y from y = mx + c"}
+
+
[email protected](scope="session")
+def ternary_func_fixture():
+    def ternary_function(ctx, m, x, c):
+        mx = pc.call_function("multiply", [m, x])
+        return pc.call_function("add", [mx, c])
+    return ternary_function
+
+
+varargs_doc = {"summary": "z=ax+by+c",
+               "description": "find z from z = ax + by + c"
+               }
+
+
[email protected](scope="session")
+def varargs_func_fixture():
+    def varargs_function(ctx, *values):
+        base_val = values[:2]
+        res = pc.call_function("add", base_val)
+        for other_val in values[2:]:
+            res = pc.call_function("add", [res, other_val])
+        return res
+    return varargs_function
+
+
[email protected](scope="session")
+def random_with_udf_ctx_func_fixture():
+    def random_with_udf_ctx(context, one, two):
+        old_pool = pa.default_memory_pool()
+        proxy_pool = pa.proxy_memory_pool(context.memory_pool)
+        pa.set_memory_pool(proxy_pool)
+        try:
+            ans = pc.add(one, two, memory_pool=proxy_pool)
+            allocated_before = proxy_pool.bytes_allocated()
+            # allocating 64 bytes
+            res = pa.array([ans.as_py()], memory_pool=proxy_pool)
+            allocated_after = proxy_pool.bytes_allocated()
+        finally:
+            pa.set_memory_pool(old_pool)
+        assert allocated_before == 0
+        assert allocated_after == 64
+        assert context.batch_length == 2

Review Comment:
   We don't need to assert this here and doing so is a little messy because now 
this function has to know about the test that calls it.



##########
python/pyarrow/tests/test_udf.py:
##########
@@ -0,0 +1,545 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+
+import pytest
+
+import pyarrow as pa
+from pyarrow import compute as pc
+
+
+# Marks all of the tests in this module
+# Ignore these with pytest ... -m 'not udf'
+# pytestmark = pytest.mark.udf
+
+unary_doc = {"summary": "add function",
+             "description": "test add function"}
+
+
[email protected](scope="session")
+def udf_context():
+    return pc._get_scalar_udf_context(pa.default_memory_pool(), 0)
+
+
[email protected](scope="session")
+def unary_func_fixture():
+    def unary_function(udf_context, scalar1):
+        return pc.call_function("add", [scalar1, 1])
+    return unary_function
+
+
+binary_doc = {"summary": "y=mx",
+              "description": "find y from y = mx"}
+
+
[email protected](scope="session")
+def binary_func_fixture():
+    def binary_function(ctx, m, x):
+        return pc.call_function("multiply", [m, x])
+    return binary_function
+
+
+ternary_doc = {"summary": "y=mx+c",
+               "description": "find y from y = mx + c"}
+
+
[email protected](scope="session")
+def ternary_func_fixture():
+    def ternary_function(ctx, m, x, c):
+        mx = pc.call_function("multiply", [m, x])
+        return pc.call_function("add", [mx, c])
+    return ternary_function
+
+
+varargs_doc = {"summary": "z=ax+by+c",
+               "description": "find z from z = ax + by + c"
+               }
+
+
[email protected](scope="session")
+def varargs_func_fixture():
+    def varargs_function(ctx, *values):
+        base_val = values[:2]
+        res = pc.call_function("add", base_val)
+        for other_val in values[2:]:
+            res = pc.call_function("add", [res, other_val])
+        return res
+    return varargs_function
+
+
[email protected](scope="session")
+def random_with_udf_ctx_func_fixture():
+    def random_with_udf_ctx(context, one, two):
+        old_pool = pa.default_memory_pool()
+        proxy_pool = pa.proxy_memory_pool(context.memory_pool)
+        pa.set_memory_pool(proxy_pool)
+        try:
+            ans = pc.add(one, two, memory_pool=proxy_pool)
+            allocated_before = proxy_pool.bytes_allocated()
+            # allocating 64 bytes
+            res = pa.array([ans.as_py()], memory_pool=proxy_pool)
+            allocated_after = proxy_pool.bytes_allocated()
+        finally:
+            pa.set_memory_pool(old_pool)
+        assert allocated_before == 0
+        assert allocated_after == 64
+        assert context.batch_length == 2
+        return res

Review Comment:
   This return value isn't correct.  You are returning an array of size 1 no 
matter what the `batch_length` was.  This violates the rules for a "scalar 
function" which must emit an item for each row.



##########
python/pyarrow/tests/test_udf.py:
##########
@@ -0,0 +1,545 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+
+import pytest
+
+import pyarrow as pa
+from pyarrow import compute as pc
+
+
+# Marks all of the tests in this module
+# Ignore these with pytest ... -m 'not udf'
+# pytestmark = pytest.mark.udf
+
+unary_doc = {"summary": "add function",
+             "description": "test add function"}

Review Comment:
   If we get rid of scalar tests then this is only used by one function so we 
can move it into the fixture body.



##########
python/pyarrow/tests/test_udf.py:
##########
@@ -0,0 +1,545 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+
+import pytest
+
+import pyarrow as pa
+from pyarrow import compute as pc
+
+
+# Marks all of the tests in this module
+# Ignore these with pytest ... -m 'not udf'
+# pytestmark = pytest.mark.udf
+
+unary_doc = {"summary": "add function",
+             "description": "test add function"}
+
+
[email protected](scope="session")
+def udf_context():

Review Comment:
   Nit: mock_udf_context?



##########
python/pyarrow/tests/test_udf.py:
##########
@@ -0,0 +1,545 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+
+import pytest
+
+import pyarrow as pa
+from pyarrow import compute as pc
+
+
+# Marks all of the tests in this module
+# Ignore these with pytest ... -m 'not udf'
+# pytestmark = pytest.mark.udf
+
+unary_doc = {"summary": "add function",
+             "description": "test add function"}
+
+
[email protected](scope="session")
+def udf_context():
+    return pc._get_scalar_udf_context(pa.default_memory_pool(), 0)
+
+
[email protected](scope="session")
+def unary_func_fixture():
+    def unary_function(udf_context, scalar1):
+        return pc.call_function("add", [scalar1, 1])
+    return unary_function
+
+
+binary_doc = {"summary": "y=mx",
+              "description": "find y from y = mx"}
+
+
[email protected](scope="session")
+def binary_func_fixture():
+    def binary_function(ctx, m, x):
+        return pc.call_function("multiply", [m, x])
+    return binary_function
+
+
+ternary_doc = {"summary": "y=mx+c",
+               "description": "find y from y = mx + c"}
+
+
[email protected](scope="session")
+def ternary_func_fixture():
+    def ternary_function(ctx, m, x, c):
+        mx = pc.call_function("multiply", [m, x])
+        return pc.call_function("add", [mx, c])
+    return ternary_function
+
+
+varargs_doc = {"summary": "z=ax+by+c",
+               "description": "find z from z = ax + by + c"
+               }
+
+
[email protected](scope="session")
+def varargs_func_fixture():
+    def varargs_function(ctx, *values):
+        base_val = values[:2]
+        res = pc.call_function("add", base_val)
+        for other_val in values[2:]:
+            res = pc.call_function("add", [res, other_val])
+        return res
+    return varargs_function
+
+
[email protected](scope="session")
+def random_with_udf_ctx_func_fixture():
+    def random_with_udf_ctx(context, one, two):
+        old_pool = pa.default_memory_pool()
+        proxy_pool = pa.proxy_memory_pool(context.memory_pool)

Review Comment:
   ```suggestion
   ```
   
   Proxy the memory pool in the calling portion (in the test) and we can assert 
it there.



##########
python/pyarrow/tests/test_udf.py:
##########
@@ -0,0 +1,545 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+
+import pytest
+
+import pyarrow as pa
+from pyarrow import compute as pc
+
+
+# Marks all of the tests in this module
+# Ignore these with pytest ... -m 'not udf'
+# pytestmark = pytest.mark.udf
+
+unary_doc = {"summary": "add function",
+             "description": "test add function"}
+
+
[email protected](scope="session")
+def udf_context():
+    return pc._get_scalar_udf_context(pa.default_memory_pool(), 0)
+
+
[email protected](scope="session")
+def unary_func_fixture():
+    def unary_function(udf_context, scalar1):
+        return pc.call_function("add", [scalar1, 1])
+    return unary_function
+
+
+binary_doc = {"summary": "y=mx",
+              "description": "find y from y = mx"}
+
+
[email protected](scope="session")
+def binary_func_fixture():
+    def binary_function(ctx, m, x):
+        return pc.call_function("multiply", [m, x])
+    return binary_function
+
+
+ternary_doc = {"summary": "y=mx+c",
+               "description": "find y from y = mx + c"}
+
+
[email protected](scope="session")
+def ternary_func_fixture():
+    def ternary_function(ctx, m, x, c):
+        mx = pc.call_function("multiply", [m, x])
+        return pc.call_function("add", [mx, c])
+    return ternary_function
+
+
+varargs_doc = {"summary": "z=ax+by+c",
+               "description": "find z from z = ax + by + c"
+               }
+
+
[email protected](scope="session")
+def varargs_func_fixture():
+    def varargs_function(ctx, *values):
+        base_val = values[:2]
+        res = pc.call_function("add", base_val)
+        for other_val in values[2:]:
+            res = pc.call_function("add", [res, other_val])
+        return res
+    return varargs_function
+
+
[email protected](scope="session")
+def random_with_udf_ctx_func_fixture():
+    def random_with_udf_ctx(context, one, two):
+        old_pool = pa.default_memory_pool()
+        proxy_pool = pa.proxy_memory_pool(context.memory_pool)
+        pa.set_memory_pool(proxy_pool)
+        try:
+            ans = pc.add(one, two, memory_pool=proxy_pool)
+            allocated_before = proxy_pool.bytes_allocated()
+            # allocating 64 bytes
+            res = pa.array([ans.as_py()], memory_pool=proxy_pool)
+            allocated_after = proxy_pool.bytes_allocated()
+        finally:
+            pa.set_memory_pool(old_pool)
+        assert allocated_before == 0
+        assert allocated_after == 64
+        assert context.batch_length == 2
+        return res
+    return random_with_udf_ctx
+
+
[email protected](scope="session")
+def const_return_func_fixture():
+    def const_return(ctx, array):
+        return 42
+    return const_return
+
+
[email protected](scope="session")
+def output_check_func_fixture():
+    def output_check(ctx, array):
+        ar = pc.call_function("add", [array, 1])
+        ar = ar.cast(pa.int32())
+        return ar
+    return output_check
+
+
[email protected](scope="session")
+def nullary_check_func_fixture():
+    def nullary_check(ctx):
+        import random

Review Comment:
   We can just import this at the top of the file.  I see no need to nest this 
import.



##########
python/pyarrow/tests/test_udf.py:
##########
@@ -0,0 +1,545 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+
+import pytest
+
+import pyarrow as pa
+from pyarrow import compute as pc
+
+
+# Marks all of the tests in this module
+# Ignore these with pytest ... -m 'not udf'
+# pytestmark = pytest.mark.udf

Review Comment:
   We probably don't need a mark since we always compile with the support.  We 
may want to depend on the dataset mark if we are going to run in datasets.



##########
python/pyarrow/tests/test_udf.py:
##########
@@ -0,0 +1,545 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+
+import pytest
+
+import pyarrow as pa
+from pyarrow import compute as pc
+
+
+# Marks all of the tests in this module
+# Ignore these with pytest ... -m 'not udf'
+# pytestmark = pytest.mark.udf
+
+unary_doc = {"summary": "add function",
+             "description": "test add function"}
+
+
[email protected](scope="session")
+def udf_context():
+    return pc._get_scalar_udf_context(pa.default_memory_pool(), 0)
+
+
[email protected](scope="session")
+def unary_func_fixture():
+    def unary_function(udf_context, scalar1):
+        return pc.call_function("add", [scalar1, 1])
+    return unary_function
+
+
+binary_doc = {"summary": "y=mx",
+              "description": "find y from y = mx"}
+
+
[email protected](scope="session")
+def binary_func_fixture():
+    def binary_function(ctx, m, x):
+        return pc.call_function("multiply", [m, x])
+    return binary_function
+
+
+ternary_doc = {"summary": "y=mx+c",
+               "description": "find y from y = mx + c"}
+
+
[email protected](scope="session")
+def ternary_func_fixture():
+    def ternary_function(ctx, m, x, c):
+        mx = pc.call_function("multiply", [m, x])
+        return pc.call_function("add", [mx, c])
+    return ternary_function
+
+
+varargs_doc = {"summary": "z=ax+by+c",
+               "description": "find z from z = ax + by + c"
+               }
+
+
[email protected](scope="session")
+def varargs_func_fixture():
+    def varargs_function(ctx, *values):
+        base_val = values[:2]
+        res = pc.call_function("add", base_val)
+        for other_val in values[2:]:
+            res = pc.call_function("add", [res, other_val])
+        return res
+    return varargs_function
+
+
[email protected](scope="session")
+def random_with_udf_ctx_func_fixture():
+    def random_with_udf_ctx(context, one, two):
+        old_pool = pa.default_memory_pool()
+        proxy_pool = pa.proxy_memory_pool(context.memory_pool)
+        pa.set_memory_pool(proxy_pool)
+        try:
+            ans = pc.add(one, two, memory_pool=proxy_pool)
+            allocated_before = proxy_pool.bytes_allocated()
+            # allocating 64 bytes
+            res = pa.array([ans.as_py()], memory_pool=proxy_pool)
+            allocated_after = proxy_pool.bytes_allocated()
+        finally:
+            pa.set_memory_pool(old_pool)
+        assert allocated_before == 0
+        assert allocated_after == 64
+        assert context.batch_length == 2
+        return res
+    return random_with_udf_ctx
+
+
[email protected](scope="session")
+def const_return_func_fixture():
+    def const_return(ctx, array):
+        return 42
+    return const_return
+
+
[email protected](scope="session")
+def output_check_func_fixture():
+    def output_check(ctx, array):
+        ar = pc.call_function("add", [array, 1])
+        ar = ar.cast(pa.int32())
+        return ar
+    return output_check
+
+
[email protected](scope="session")
+def nullary_check_func_fixture():
+    def nullary_check(ctx):
+        import random
+        val = random.randint(0, 10)
+        return pa.scalar(val)
+    return nullary_check
+
+
[email protected](scope="session")
+def add_const_func_fixture():

Review Comment:
   There is no need for this fixture because the only tests that use it do not 
successfully register the function.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to