0

I know there's this question. However the code I want is a little different.

[dependencies]

ordered-float: "4.4"

polars: {version="0.43", features = ["lazy", "parquet", "dtype-struct", "dtype-u8", "round_series"]}

itertools = "0.13"

chrono: "0.4"

pyo3: { version = "0.21", features = ["extension-module"] }

pyo3-polars: "0.18"

I want this to work:

use pyo3::prelude::*;
use pyo3::{Python, IntoPy};
use polars::prelude::*;
use pyo3_polars::PyDataFrame;

fn get_df() -> DataFrame{
    let mut symbols: Vec<i32> = Vec::new();
    let mut prices: Vec<i32> = Vec::new();
    df!(
        "Symbol" => &symbols,
        "Price" => &prices
    ).unwrap()
}
fn to_python() -> PyResult<PyDataFrame> {
    let df:DataFrame = get_df(); 
    let pydf = PyDataFrame(df);
    Python::with_gil(|py| {
        Ok(pydf)
    })
}

However I got:

error[E0308]: mismatched types
   --> src/lib.rs:62:32
    |
62  |         let pydf = PyDataFrame(df);
    |                    ----------- ^^ expected `polars_core::frame::DataFrame`, found `polars::prelude::DataFrame`
    |                    |
    |                    arguments to this struct are incorrect
    |
    = note: `polars::prelude::DataFrame` and `polars_core::frame::DataFrame` have similar names, but are actually distinct types

How to solve this? Thank you!

3
  • 2
    It looks like you've got different version of polars. Please put the output of cargo tree. Commented Nov 25, 2024 at 12:33
  • @ChayimFriedman Here is the cargo tree: gist.github.com/xuJ14/85c67a168a93f130c4296b9994d3aa4a Commented Nov 26, 2024 at 2:04
  • @ChayimFriedman You are right! The polars in pyo3-polars is different with my cargo.toml. Thank you! Commented Nov 26, 2024 at 4:56

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.