Skip to content

Commit

Permalink
split python and arrow
Browse files Browse the repository at this point in the history
  • Loading branch information
«ratal» committed Mar 6, 2024
1 parent 14caa2e commit ab2415a
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 24 deletions.
23 changes: 1 addition & 22 deletions src/data_holder/arrow_helpers.rs
Original file line number Diff line number Diff line change
@@ -1,27 +1,6 @@
//! helpers for arrow
use std::sync::Arc;

use arrow::array::{
make_array, Array, ArrayData, BinaryArray, LargeBinaryArray, LargeStringArray, StringArray,
};
use arrow::array::{Array, BinaryArray, LargeBinaryArray, LargeStringArray, StringArray};
use arrow::datatypes::DataType;
use arrow::pyarrow::PyArrowType;
use pyo3::prelude::*;
use pyo3::PyResult;

/// Take an arrow array from python and convert it to a rust arrow array.
/// This operation does not copy data.
#[allow(dead_code)]
pub fn array_to_rust(arrow_array: PyArrowType<ArrayData>) -> PyResult<Arc<dyn Array>> {
// prepare a pointer to receive the Array struct
let array = arrow_array.0; // Extract from PyArrowType wrapper
Ok(make_array(array))
}

/// Arrow array to Python.
pub(crate) fn to_py_array(_: Python, array: Arc<dyn Array>) -> PyResult<PyArrowType<ArrayData>> {
Ok(PyArrowType(array.into_data()))
}

/// returns the number of bits corresponding to the array's datatype
pub fn arrow_bit_count(array: &dyn Array) -> u32 {
Expand Down
1 change: 1 addition & 0 deletions src/export/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
//! Module to export mdf files to other file formats.
pub mod numpy;
pub mod python_arrow_helpers;
//pub mod parquet;
pub mod polars;
// pub mod tensor;
2 changes: 1 addition & 1 deletion src/export/polars.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use std::sync::Arc;
use arrow::array::Array;
use pyo3::{types::PyList, PyObject, PyResult, ToPyObject};

use crate::data_holder::arrow_helpers::to_py_array;
use crate::export::python_arrow_helpers::to_py_array;

/// converts rust arrow array into python polars series
#[allow(dead_code)]
Expand Down
21 changes: 21 additions & 0 deletions src/export/python_arrow_helpers.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//! helpers for arrow use with python
use std::sync::Arc;

use arrow::array::{make_array, Array, ArrayData};
use arrow::pyarrow::PyArrowType;
use pyo3::prelude::*;
use pyo3::PyResult;

/// Take an arrow array from python and convert it to a rust arrow array.
/// This operation does not copy data.
#[allow(dead_code)]
pub fn array_to_rust(arrow_array: PyArrowType<ArrayData>) -> PyResult<Arc<dyn Array>> {
// prepare a pointer to receive the Array struct
let array = arrow_array.0; // Extract from PyArrowType wrapper
Ok(make_array(array))
}

/// Arrow array to Python.
pub(crate) fn to_py_array(_: Python, array: Arc<dyn Array>) -> PyResult<PyArrowType<ArrayData>> {
Ok(PyArrowType(array.into_data()))
}
2 changes: 1 addition & 1 deletion src/mdfr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
use std::collections::HashSet;
use std::fmt::Write;

use crate::data_holder::arrow_helpers::array_to_rust;
use crate::export::polars::rust_arrow_to_py_series;
use crate::export::python_arrow_helpers::array_to_rust;
use crate::mdfinfo::MdfInfo;
use crate::mdfreader::MasterSignature;
use crate::mdfreader::Mdf;
Expand Down

0 comments on commit ab2415a

Please sign in to comment.