9

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!

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. Commented Jun 15, 2022 at 21:09
  • lazy is not enabled by default. do you have the lazy apis enabled in your Cargo.toml? Commented Jun 16, 2022 at 5:57
  • @CoryGrinstead - please see edited question for Cargo.toml Commented Jun 16, 2022 at 6:12
  • @cdhowie - 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... Commented Jun 16, 2022 at 17:42
  • @cdhowie - 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. Commented Jun 16, 2022 at 17:46

1 Answer 1

5

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"]}

Sign up to request clarification or add additional context in comments.

2 Comments

yes - that's solved it - thanks! wonders where are "feature flags" documented, crates.io?
the official docs have some more info on "features" & how the conditional compilation works. doc.rust-lang.org/cargo/reference/features.html

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.