You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@arrow.apache.org by we...@apache.org on 2020/06/17 20:37:59 UTC
[arrow] branch master updated: ARROW-9162: [Python] Expose
Add/Subtract/Multiply arithmetic kernels
This is an automated email from the ASF dual-hosted git repository.
wesm pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/arrow.git
The following commit(s) were added to refs/heads/master by this push:
new c137c3a ARROW-9162: [Python] Expose Add/Subtract/Multiply arithmetic kernels
c137c3a is described below
commit c137c3a1462b90ec4d01ae42dfdee9edc154d6df
Author: Krisztián Szűcs <sz...@gmail.com>
AuthorDate: Wed Jun 17 15:37:40 2020 -0500
ARROW-9162: [Python] Expose Add/Subtract/Multiply arithmetic kernels
Closes #7473 from kszucs/pyarithmetic
Authored-by: Krisztián Szűcs <sz...@gmail.com>
Signed-off-by: Wes McKinney <we...@apache.org>
---
python/pyarrow/compute.py | 10 ++++++++++
python/pyarrow/tests/test_compute.py | 25 ++++++++++++++++++++++++-
2 files changed, 34 insertions(+), 1 deletion(-)
diff --git a/python/pyarrow/compute.py b/python/pyarrow/compute.py
index d656403..26cf37a 100644
--- a/python/pyarrow/compute.py
+++ b/python/pyarrow/compute.py
@@ -91,10 +91,20 @@ def _simple_unary_function(name):
return func
+def _simple_binary_function(name):
+ def func(left, right):
+ return call_function(name, [left, right])
+ return func
+
+
ascii_length = _simple_unary_function('ascii_length')
ascii_upper = _simple_unary_function('ascii_upper')
ascii_lower = _simple_unary_function('ascii_lower')
+add = _simple_binary_function('add')
+subtract = _simple_binary_function('subtract')
+multiply = _simple_binary_function('multiply')
+
def sum(array):
"""
diff --git a/python/pyarrow/tests/test_compute.py b/python/pyarrow/tests/test_compute.py
index a1607e8..6a7e7d0 100644
--- a/python/pyarrow/tests/test_compute.py
+++ b/python/pyarrow/tests/test_compute.py
@@ -299,7 +299,6 @@ def test_compare_scalar(typ):
def test_compare_chunked_array_mixed():
-
arr = pa.array([1, 2, 3, 4, None])
arr_chunked = pa.chunked_array([[1, 2, 3], [4, None]])
arr_chunked2 = pa.chunked_array([[1, 2], [3, 4, None]])
@@ -312,3 +311,27 @@ def test_compare_chunked_array_mixed():
arr_chunked == arr_chunked2,
]:
assert result.equals(expected)
+
+
+def test_arithmetic_add():
+ left = pa.array([1, 2, 3, 4, 5])
+ right = pa.array([0, -1, 1, 2, 3])
+ result = pa.compute.add(left, right)
+ expected = pa.array([1, 1, 4, 6, 8])
+ assert result.equals(expected)
+
+
+def test_arithmetic_subtract():
+ left = pa.array([1, 2, 3, 4, 5])
+ right = pa.array([0, -1, 1, 2, 3])
+ result = pa.compute.subtract(left, right)
+ expected = pa.array([1, 3, 2, 2, 2])
+ assert result.equals(expected)
+
+
+def test_arithmetic_multiply():
+ left = pa.array([1, 2, 3, 4, 5])
+ right = pa.array([0, -1, 1, 2, 3])
+ result = pa.compute.multiply(left, right)
+ expected = pa.array([0, -2, 3, 8, 15])
+ assert result.equals(expected)