scouter_client/data_utils/
mod.rs

1use crate::error::DataError;
2use pyo3::prelude::*;
3pub mod arrow;
4pub mod base;
5
6pub mod numpy;
7pub mod pandas;
8pub mod polars;
9pub mod types;
10
11pub use arrow::*;
12pub use base::*;
13pub use numpy::*;
14pub use pandas::*;
15pub use polars::*;
16use scouter_types::DataType;
17pub use types::*;
18
19pub enum DataConverterEnum {
20    Arrow(ArrowDataConverter),
21    Numpy(NumpyDataConverter),
22    Pandas(PandasDataConverter),
23    Polars(PolarsDataConverter),
24}
25
26impl DataConverterEnum {
27    /// Convert the data to the appropriate format
28    ///
29    /// # Arguments
30    ///
31    /// * `data_type` - The type of data to convert
32    /// * `data` - The data to convert
33    ///
34    /// # Returns
35    ///
36    /// The converted data
37    pub fn convert_data<'py>(
38        py: Python<'py>,
39        data_type: &DataType,
40        data: &Bound<'py, PyAny>,
41    ) -> Result<ConvertedData<'py>, DataError> {
42        match data_type {
43            DataType::Arrow => ArrowDataConverter::prepare_data(py, data),
44            DataType::Numpy => NumpyDataConverter::prepare_data(py, data),
45            DataType::Pandas => PandasDataConverter::prepare_data(py, data),
46            DataType::Polars => PolarsDataConverter::prepare_data(py, data),
47            _ => Err(DataError::UnsupportedDataTypeError(data_type.to_string())),
48        }
49    }
50}