lazy() method not found in `polars::prelude::DataFrame`
Asked Answered
P

1

8

I am writing an extern lib for Polars in Rust (for consumption by Raku::Dan) and would like to get out an opaque container for a LazyFrame object by calling df.lazy().

use polars::prelude::*;//{CsvReader, DataType, DataFrame, Series};
use polars::prelude::{Result as PolarResult};
use polars_lazy::prelude::*;

// LazyFrame Container

pub struct LazyFrameC {
    lf: LazyFrame,
}

impl LazyFrameC {
    fn new(ptr: *mut DataFrameC) -> LazyFrameC {
        LazyFrameC {
            lf: (*ptr).df.lazy(),
        }
    }
}
// extern functions for LazyFrame Container
#[no_mangle]
pub extern "C" fn lf_new(ptr: *mut DataFrameC) -> *mut LazyFrameC {
    let df_c = unsafe {
        assert!(!ptr.is_null());
        &mut *ptr
    };

    Box::into_raw(Box::new(LazyFrameC::new(ptr)))
}

Does not work, gives the error:

error[E0599]: no method named `lazy` found for struct `polars::prelude::DataFrame` in the current scope
   --> src/lib.rs:549:27
    |
549 |             lf: (*ptr).df.lazy(), 
    |                           ^^^^ method not found in `polars::prelude::DataFrame`

Here's my Cargo.toml (edit)...

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

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
libc = "0.2.126"
polars = "0.21.1"
polars-core = "0.22.7"
polars-lazy = "0.22.7"

[lib]
name = "dan"
path = "src/lib.rs"
crate-type = ["cdylib"

Any steer on pinning down the correct library would be much appreciated!

Pneuma answered 15/6, 2022 at 21:2 Comment(5)
I can't test with this code because it's missing a definition of DataFrameC. Note also that you are missing #[repr(C)] on LazyFrameC.Colo
lazy is not enabled by default. do you have the lazy apis enabled in your Cargo.toml?Severn
@CoryGrinstead - please see edited question for Cargo.tomlPneuma
@Colo - yes this example is a snippet from ~400 lines and not golfed ... I was hoping to benefit from experienced eyeballs in the first instance and it seems that the missing Cargo.toml was in that category...Pneuma
@Colo - I am not using #[repr(C)] on LazyFrameC since I am implementing a proxy pattern with opaque objects ... so the only thing I need on the raku side for this Container is a ptr and then implement a method call and callback interface. Where I do pass data (args and return) I use CStr and CArray and native C types like i32.Pneuma
S
4

Dataframe::lazy is feature flagged behind the lazy feature

try changing your cargo.toml from polars = "0.22.1" to polars = {version = "0.22.1", features = ["lazy"]}

Severn answered 16/6, 2022 at 6:39 Comment(2)
yes - that's solved it - thanks! wonders where are "feature flags" documented, crates.io?Pneuma
the official docs have some more info on "features" & how the conditional compilation works. doc.rust-lang.org/cargo/reference/features.htmlSevern

© 2022 - 2024 — McMap. All rights reserved.