4

Here we go again with another problem I can't solve, although it sound so easy.

I am following Rust polars documentation about dataframes: https://docs.rs/polars/0.14.2/polars/frame/struct.DataFrame.html I am trying to simply implement the easies thing they wrote, namely create a dataframe and convert to 2D array with to_ndarray:

use polars::prelude::*;
use polars_core::prelude::*;
use polars::frame::DataFrame;

fn main() {
    println!("Defining a dataframe");
    let a = UInt32Chunked::new_from_slice("a", &[1, 2, 3]).into_series();
    let b = Float64Chunked::new_from_slice("b", &[10., 8., 6.]).into_series();
    
    let df = DataFrame::new(vec![a, b]).unwrap();
    let ndarray = df.to_ndarray::<Float64Type>().unwrap();
    println!("{:?}", ndarray);
}

When I am trying to run this code I have the following error:

error[E0599]: no method named `to_ndarray` found for struct `DataFrame` in the current scope
  --> src/main.rs:42:22
   |
42 |     let ndarray = df.to_ndarray::<Float64Type>().unwrap();
   |                      ^^^^^^^^^^ method not found in `DataFrame`

What should I import to use to_ndarray?

pythonic833
  • 3,054
  • 1
  • 12
  • 27
FrankNrg92
  • 71
  • 4
  • 1
    Did you enable the feature `ndarray` in your `Cargo.toml` file? – L. F. Jun 22 '21 at 10:51
  • 1
    Hi @L.F. In my `Cargo.toml` I have: ```[dependencies] polars = "0.14.2" polars-core = "0.14.2" arrow = "4.3.0" [features] ndarray = ["polars-core/ndarray"] ``` Plus the `package` info. – FrankNrg92 Jun 22 '21 at 11:03
  • You're defining a new feature `ndarray` for your own crate instead of enabling the `ndarray` feature of `polars`. Here's how you would do the latter: [Dependency features](https://doc.rust-lang.org/cargo/reference/features.html#dependency-features) – L. F. Jun 22 '21 at 11:07
  • 1
    You're right, I confused the way to import `features` for a package. Thanks very much @L.F. – FrankNrg92 Jun 22 '21 at 12:43

0 Answers0