-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
9 changed files
with
212 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
# Note: importing with | ||
# `from arro3.core import Array` | ||
# will cause Array to be included in the generated docs in this module. | ||
import arro3.core as core | ||
import arro3.core.types as types | ||
|
||
def add(lhs: types.ArrowArrayExportable, rhs: types.ArrowArrayExportable) -> core.Array: | ||
"""Perform `lhs + rhs`, returning an error on overflow""" | ||
|
||
def add_wrapping( | ||
lhs: types.ArrowArrayExportable, rhs: types.ArrowArrayExportable | ||
) -> core.Array: | ||
"""Perform `lhs + rhs`, wrapping on overflow for DataType::is_integer""" | ||
|
||
def div(lhs: types.ArrowArrayExportable, rhs: types.ArrowArrayExportable) -> core.Array: | ||
"""Perform `lhs / rhs`""" | ||
|
||
def mul(lhs: types.ArrowArrayExportable, rhs: types.ArrowArrayExportable) -> core.Array: | ||
"""Perform `lhs * rhs`, returning an error on overflow""" | ||
|
||
def mul_wrapping( | ||
lhs: types.ArrowArrayExportable, rhs: types.ArrowArrayExportable | ||
) -> core.Array: | ||
"""Perform `lhs * rhs`, wrapping on overflow for DataType::is_integer""" | ||
|
||
def neg(array: types.ArrowArrayExportable) -> core.Array: | ||
"""Negates each element of array, returning an error on overflow""" | ||
|
||
def neg_wrapping(array: types.ArrowArrayExportable) -> core.Array: | ||
"""Negates each element of array, wrapping on overflow for DataType::is_integer""" | ||
|
||
def rem(lhs: types.ArrowArrayExportable, rhs: types.ArrowArrayExportable) -> core.Array: | ||
"""Perform `lhs % rhs`""" | ||
|
||
def sub(lhs: types.ArrowArrayExportable, rhs: types.ArrowArrayExportable) -> core.Array: | ||
"""Perform `lhs - rhs`, returning an error on overflow""" | ||
|
||
def sub_wrapping( | ||
lhs: types.ArrowArrayExportable, rhs: types.ArrowArrayExportable | ||
) -> core.Array: | ||
"""Perform `lhs - rhs`, wrapping on overflow for DataType::is_integer""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
use arrow::compute::kernels::numeric; | ||
use pyo3::prelude::*; | ||
use pyo3_arrow::error::PyArrowResult; | ||
use pyo3_arrow::input::AnyDatum; | ||
use pyo3_arrow::PyArray; | ||
|
||
#[pyfunction] | ||
pub fn add(py: Python, lhs: AnyDatum, rhs: AnyDatum) -> PyArrowResult<PyObject> { | ||
Ok(PyArray::from_array_ref(numeric::add(&lhs, &rhs)?).to_arro3(py)?) | ||
} | ||
|
||
#[pyfunction] | ||
pub fn add_wrapping(py: Python, lhs: AnyDatum, rhs: AnyDatum) -> PyArrowResult<PyObject> { | ||
Ok(PyArray::from_array_ref(numeric::add_wrapping(&lhs, &rhs)?).to_arro3(py)?) | ||
} | ||
|
||
#[pyfunction] | ||
pub fn div(py: Python, lhs: AnyDatum, rhs: AnyDatum) -> PyArrowResult<PyObject> { | ||
Ok(PyArray::from_array_ref(numeric::div(&lhs, &rhs)?).to_arro3(py)?) | ||
} | ||
|
||
#[pyfunction] | ||
pub fn mul(py: Python, lhs: AnyDatum, rhs: AnyDatum) -> PyArrowResult<PyObject> { | ||
Ok(PyArray::from_array_ref(numeric::mul(&lhs, &rhs)?).to_arro3(py)?) | ||
} | ||
|
||
#[pyfunction] | ||
pub fn mul_wrapping(py: Python, lhs: AnyDatum, rhs: AnyDatum) -> PyArrowResult<PyObject> { | ||
Ok(PyArray::from_array_ref(numeric::mul_wrapping(&lhs, &rhs)?).to_arro3(py)?) | ||
} | ||
|
||
#[pyfunction] | ||
pub fn neg(py: Python, array: PyArray) -> PyArrowResult<PyObject> { | ||
Ok(PyArray::from_array_ref(numeric::neg(array.as_ref())?).to_arro3(py)?) | ||
} | ||
|
||
#[pyfunction] | ||
pub fn neg_wrapping(py: Python, array: PyArray) -> PyArrowResult<PyObject> { | ||
Ok(PyArray::from_array_ref(numeric::neg_wrapping(array.as_ref())?).to_arro3(py)?) | ||
} | ||
|
||
#[pyfunction] | ||
pub fn rem(py: Python, lhs: AnyDatum, rhs: AnyDatum) -> PyArrowResult<PyObject> { | ||
Ok(PyArray::from_array_ref(numeric::rem(&lhs, &rhs)?).to_arro3(py)?) | ||
} | ||
|
||
#[pyfunction] | ||
pub fn sub(py: Python, lhs: AnyDatum, rhs: AnyDatum) -> PyArrowResult<PyObject> { | ||
Ok(PyArray::from_array_ref(numeric::sub(&lhs, &rhs)?).to_arro3(py)?) | ||
} | ||
|
||
#[pyfunction] | ||
pub fn sub_wrapping(py: Python, lhs: AnyDatum, rhs: AnyDatum) -> PyArrowResult<PyObject> { | ||
Ok(PyArray::from_array_ref(numeric::sub_wrapping(&lhs, &rhs)?).to_arro3(py)?) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import arro3.compute as ac | ||
import pyarrow as pa | ||
from arro3.core import Array, DataType | ||
|
||
|
||
def test_add(): | ||
arr1 = Array([1, 2, 3], DataType.int16()) | ||
assert ac.min(arr1).as_py() == 1 | ||
|
||
arr2 = Array([3, 2, 0], DataType.int16()) | ||
assert ac.min(arr2).as_py() == 0 | ||
|
||
add1 = ac.add(arr1, arr2) | ||
assert pa.array(add1) == pa.array(Array([4, 4, 3], DataType.int16())) | ||
|
||
s = arr1[0] | ||
add2 = ac.add(arr1, s) | ||
assert pa.array(add2) == pa.array(Array([2, 3, 4], DataType.int16())) |