Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AttributeError for pyarrow.lib.Array while working with PyDataFrame in pyo3 #115

Open
rahul-a-t opened this issue Nov 5, 2024 · 0 comments

Comments

@rahul-a-t
Copy link

rahul-a-t commented Nov 5, 2024

Hello I am a beginner in Rust while exploring with Polars dataframe in rust I encountored an error where I am not able to transfer my dataframe from rust to python

This is My Rust Code

use pyo3::prelude::*;
use polars::prelude::*;
use pyo3_polars::PyDataFrame;

#[pyfunction]
pub fn read_file(filepath: &str) ->  PyResult<PyDataFrame> {
    let df = CsvReadOptions::default()
    .try_into_reader_with_file_path(Some(filepath.into()))
    .unwrap()
    .finish()
    .unwrap();
   
    // let df = {
        // some work on the dataframe here
        // todo!()
   //  };
    println!(df ==>{}, df)
    Ok(PyDataFrame(df))
}

#[pymodule]
fn rust_modules(_py: Python, m: &Bound<'_, PyModule>) -> PyResult<()> {
    m.add_function(wrap_pyfunction!(polars_modules::read_file, m)?)?;
    Ok(())
}



###This My Python Code

import rust_modules
import polars as pl
 pg=rust_modules.read_file("/home/code/rust_modules/src/data/path.csv")
  print(f"pfg >>> {pg}")

The Error That I am Getting

image

thread '<unnamed>' panicked at /home/.cargo/registry/src/index.crates.io-6f17d22bba15001f/pyo3-polars-0.18.0/src/types.rs:296:57:
called `Result::unwrap()` on an `Err` value: PyErr { type: <class 'AttributeError'>, value: AttributeError("type object 'pyarrow.lib.Array' has no attribute '_import_arrow_from_c'"), traceback: None }
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
Traceback (most recent call last):
  File "/home/code/rust_modules/test2.py", line 9, in <module>
    pg=rust_modules.read_file("/home/code/rust_modules/src/data/path.csv")
pyo3_runtime.PanicException: called `Result::unwrap()` on an `Err` value: PyErr { type: <class 'AttributeError'>, value: AttributeError("type object 'pyarrow.lib.Array' has no attribute '_import_arrow_from_c'"), traceback: None }`

This is my cargo.toml file

[package]
name = "rust_modules"
version = "0.1.0"
edition = "2021"


[lib]
name = "rust_modules"
crate-type = ["cdylib"]

[dependencies]
log = "0.4.22"
polars = "0.44.2"
pyo3 = { version = "0.21.0", features = ["extension-module"] }
pyo3-polars = "0.18.0"

I have tried uninstalling as well as installing pyarrow
My work Enviornment is Ubuntu 20.04.5 LTS x86_64
I have Python Packages
polars 0.18.15
pyarrow 18.0.0
numpy 1.26.4

Please Help

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant