Skip to content

Commit

Permalink
Add compute and internal modules (#12)
Browse files Browse the repository at this point in the history
* Add compute and internal modules

* implement concat

* simplify return

* Add to_python methods

* Add README file
  • Loading branch information
kylebarron authored May 29, 2024
1 parent ee244ae commit 913ca39
Show file tree
Hide file tree
Showing 43 changed files with 2,681 additions and 116 deletions.
1,191 changes: 1,191 additions & 0 deletions arro3-compute/Cargo.lock

Large diffs are not rendered by default.

27 changes: 27 additions & 0 deletions arro3-compute/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
[package]
name = "arro3-compute"
version = "0.1.0"
authors = ["Kyle Barron <[email protected]>"]
edition = "2021"
description = "Rust-based compute kernels for Arrow in Python."
readme = "README.md"
repository = "https://github.com/kylebarron/arro3"
license = "MIT OR Apache-2.0"
keywords = ["python", "arrow"]
categories = []
rust-version = "1.75"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[lib]
name = "_rust"
crate-type = ["cdylib"]

[dependencies]
arrow-array = "51"
arrow-buffer = "51"
arrow-schema = "51"
arrow-select = "51"
arrow = { version = "51", features = ["ffi"] }
pyo3 = { version = "0.20.0", features = ["abi3-py38"] }
thiserror = "1"
arro3-internal = { path = "../arro3-internal" }
File renamed without changes.
25 changes: 25 additions & 0 deletions arro3-compute/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
[build-system]
requires = ["maturin>=1.4.0,<2.0"]
build-backend = "maturin"

[project]
name = "arro3-compute"
requires-python = ">=3.8"
dependencies = ["arro3-core"]
classifiers = [
"Programming Language :: Rust",
"Programming Language :: Python :: Implementation :: CPython",
"Programming Language :: Python :: Implementation :: PyPy",
]

[tool.maturin]
features = ["pyo3/extension-module"]
module-name = "arro3.compute._rust"
python-source = "python"

[tool.poetry]
name = "arro3-compute"
version = "0.0.0"
description = ""
authors = []
packages = [{ include = "python/arro3/compute" }]
4 changes: 4 additions & 0 deletions arro3-compute/python/arro3/compute/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
from ._rust import *
from ._rust import ___version

__version__: str = ___version()
File renamed without changes.
Empty file.
12 changes: 12 additions & 0 deletions arro3-compute/src/concat.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
use arro3_internal::array::PyArray;
use arro3_internal::chunked::PyChunkedArray;
use arro3_internal::error::PyArrowResult;
use pyo3::prelude::*;

#[pyfunction]
pub fn concat(input: PyChunkedArray) -> PyArrowResult<PyObject> {
let (chunks, field) = input.into_inner();
let array_refs = chunks.iter().map(|arr| arr.as_ref()).collect::<Vec<_>>();
let concatted = arrow_select::concat::concat(array_refs.as_slice())?;
Python::with_gil(|py| PyArray::new(concatted, field).to_python(py))
}
20 changes: 20 additions & 0 deletions arro3-compute/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
use pyo3::prelude::*;

pub mod concat;

const VERSION: &str = env!("CARGO_PKG_VERSION");

#[pyfunction]
fn ___version() -> &'static str {
VERSION
}

/// A Python module implemented in Rust.
#[pymodule]
fn _rust(_py: Python, m: &PyModule) -> PyResult<()> {
m.add_wrapped(wrap_pyfunction!(___version))?;

m.add_wrapped(wrap_pyfunction!(concat::concat))?;

Ok(())
}
8 changes: 8 additions & 0 deletions arro3-core/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 9 additions & 8 deletions arro3-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ name = "arro3-core"
version = "0.1.0"
authors = ["Kyle Barron <[email protected]>"]
edition = "2021"
description = "Efficient, vectorized geospatial operations in Python."
description = "Core library for representing Arrow data in Python."
readme = "README.md"
repository = "https://github.com/geoarrow/geoarrow-rs"
repository = "https://github.com/kylebarron/arro3"
license = "MIT OR Apache-2.0"
keywords = ["python", "arrow"]
categories = []
Expand All @@ -17,10 +17,11 @@ name = "_rust"
crate-type = ["cdylib"]

[dependencies]
arrow-array = "51"
arrow-buffer = "51"
arrow-schema = "51"
arrow = { version = "51", features = ["ffi"] }
arro3-internal = { path = "../arro3-internal" }
# arrow-array = "51"
# arrow-buffer = "51"
# arrow-schema = "51"
# arrow = { version = "51", features = ["ffi"] }
pyo3 = { version = "0.20.0", features = ["abi3-py38"] }
numpy = { version = "0.20", features = ["half"] }
thiserror = "1"
# numpy = { version = "0.20", features = ["half"] }
# thiserror = "1"
5 changes: 0 additions & 5 deletions arro3-core/src/ffi/to_python/mod.rs

This file was deleted.

31 changes: 0 additions & 31 deletions arro3-core/src/ffi/to_python/schema.rs

This file was deleted.

25 changes: 7 additions & 18 deletions arro3-core/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,5 @@
use pyo3::prelude::*;

pub mod array;
pub mod chunked;
pub mod error;
pub mod ffi;
pub mod field;
pub mod interop;
pub mod record_batch;
pub mod record_batch_reader;
pub mod schema;
pub mod table;

const VERSION: &str = env!("CARGO_PKG_VERSION");

#[pyfunction]
Expand All @@ -23,13 +12,13 @@ fn ___version() -> &'static str {
fn _rust(_py: Python, m: &PyModule) -> PyResult<()> {
m.add_wrapped(wrap_pyfunction!(___version))?;

m.add_class::<array::PyArray>()?;
m.add_class::<chunked::PyChunkedArray>()?;
m.add_class::<field::PyField>()?;
m.add_class::<record_batch::PyRecordBatch>()?;
m.add_class::<record_batch_reader::PyRecordBatchReader>()?;
m.add_class::<schema::PySchema>()?;
m.add_class::<table::PyTable>()?;
m.add_class::<arro3_internal::array::PyArray>()?;
m.add_class::<arro3_internal::chunked::PyChunkedArray>()?;
m.add_class::<arro3_internal::field::PyField>()?;
m.add_class::<arro3_internal::record_batch::PyRecordBatch>()?;
m.add_class::<arro3_internal::record_batch_reader::PyRecordBatchReader>()?;
m.add_class::<arro3_internal::schema::PySchema>()?;
m.add_class::<arro3_internal::table::PyTable>()?;

Ok(())
}
Loading

0 comments on commit 913ca39

Please sign in to comment.