【问题标题】:lazy() method not found in `polars::prelude::DataFrame`在 `polars::prelude::DataFrame` 中找不到 lazy() 方法
【发布时间】:2022-12-22 00:21:39
【问题描述】:

我正在为 Rust 中的 Polars 编写一个外部库(供 Raku::Dan 使用),并希望通过调用 df.lazy() 为 LazyFrame 对象取出一个不透明的容器。

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)))
}

不起作用,给出错误:

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`

这是我的 Cargo.toml(编辑)...

[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"

任何关于确定正确库的指导将不胜感激!

【问题讨论】:

  • 我无法使用此代码进行测试,因为它缺少 DataFrameC 的定义。另请注意,您在 LazyFrameC 上缺少 #[repr(C)]
  • 默认情况下不启用惰性。你的Cargo.toml 是否启用了惰性 API?
  • @CoryGrinstead - 请查看 Cargo.toml 的已编辑问题
  • @cdhowie - 是的,这个例子是来自 ~400 行的 sn-p 而不是打高尔夫球......我希望首先从有经验的眼球中受益,而且似乎丢失的 Cargo.toml 属于那个类别......
  • @cdhowie - 我没有在 LazyFrameC 上使用 #[repr(C)],因为我正在使用不透明对象实现代理模式......所以我在 raku 端为此容器唯一需要的是一个 ptr,然后实现一个方法调用和回调接口.在传递数据(args 和返回值)的地方,我使用 CStrCArray 以及 i32 等原生 C 类型。

标签: rust raku rust-polars


【解决方案1】:

Dataframe::lazy 被标记在 lazy 功能后面

尝试改变你的 cargo.toml 从 polars = "0.22.1"polars = {version = "0.22.1", features = ["lazy"]}

【讨论】:

猜你喜欢
  • 2023-01-11
  • 2023-01-07
  • 2022-12-26
  • 2022-10-08
  • 2022-12-18
  • 2022-08-24
  • 2022-09-23
  • 2012-07-27
  • 2023-02-09
相关资源
最近更新 更多