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!
cargo tree.cargo tree: gist.github.com/xuJ14/85c67a168a93f130c4296b9994d3aa4a