6

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!

librasteve
  • 6,832
  • 8
  • 30
  • 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`. – cdhowie Jun 15 '22 at 21:09
  • lazy is not enabled by default. do you have the lazy apis enabled in your `Cargo.toml`? – Cory Grinstead Jun 16 '22 at 05:57
  • @CoryGrinstead - please see edited question for Cargo.toml – librasteve Jun 16 '22 at 06: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... – librasteve Jun 16 '22 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```. – librasteve Jun 16 '22 at 17:46

1 Answers1

3

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

Cory Grinstead
  • 511
  • 3
  • 16
  • yes - that's solved it - thanks! wonders where are "feature flags" documented, crates.io? – librasteve Jun 16 '22 at 07:21
  • 1
    the official docs have some more info on "features" & how the conditional compilation works. https://doc.rust-lang.org/cargo/reference/features.html – Cory Grinstead Jun 16 '22 at 19:49