Rust Polars-从DF.Column而不是AN'&&&'获得结构系列。参考

发布于 2025-02-02 19:20:08 字数 1616 浏览 4 评论 0原文

我正在构建一个从Raku Nativecall到Rust Porars的接口,以增强凉爽的Arrow2性能。在高水平上,我想将诸如DataFrame和系列等匹配容器的属性之类的等极点结构合作。因此,要做df.column我想要类似的东西...

use polars::prelude::*;//{CsvReader, DataType, Field, Schema, DataFrame,};
use polars::prelude::{Result as PolarResult};
use polars::frame::DataFrame;
use polars::datatypes::DataType;

pub struct DataFrameC {
    df: DataFrame,
}

impl DataFrameC {
    fn new() -> DataFrameC {
        DataFrameC {
            df: DataFrame::default(),
        }   
    }   

    fn column(&self, string: String) -> Series {
        //let colin = self.df.column(&string).unwrap().head(Some(23));
        let colin = self.df.column(&string).unwrap()
        println!{"{}", colin};
        colin
    }
}

(系列的类似方法 - 因此,完成此FN的下一步是制作seriper :: new(),然后se.set(Colin)),

但是 - 我无法确定如何确定PORARS系列&引用一个普通系列(我尝试过.deref()和.from_ptr(),但是这些方法不存在)。

我已经解决了该系列。head()确实返回系列struct--所以//线按预期工作(但不是整个系列!)

我一直遇到此错误:

error[E0308]: mismatched types
  --> src/lib.rs:92:9
   |
88 |     fn column(&self, string: String) -> Series {
   |                                         ------ expected `polars::prelude::Series` because of return type
...
92 |         colin
   |         ^^^^^ expected struct `polars::prelude::Series`, found `&polars::prelude::Series`

For more information about this error, try `rustc --explain E0308`.
error: could not compile `dan` due to previous error

是否有做这个deref操作的成语?

任何建议都非常感谢!

I am building an interface from Raku NativeCall to Rust Polars to get that cool Arrow2 performance boost. At the high level I would like to work with Polars structs such as DataFrame and Series as attributes of matching containers. So to do df.column I would like something like this...

use polars::prelude::*;//{CsvReader, DataType, Field, Schema, DataFrame,};
use polars::prelude::{Result as PolarResult};
use polars::frame::DataFrame;
use polars::datatypes::DataType;

pub struct DataFrameC {
    df: DataFrame,
}

impl DataFrameC {
    fn new() -> DataFrameC {
        DataFrameC {
            df: DataFrame::default(),
        }   
    }   

    fn column(&self, string: String) -> Series {
        //let colin = self.df.column(&string).unwrap().head(Some(23));
        let colin = self.df.column(&string).unwrap()
        println!{"{}", colin};
        colin
    }
}

(similar approach for Series - so next steps to complete this fn is to make a Series::new() and then se.set(colin))

BUT - I can't work out how to deref a Polars Series & reference to a plain Series (I have tried .Deref() and .from_ptr() but these methods do not exist).

I have worked out that Series.head() does return a Series struct --- so the // line works as intended (but not the whole Series!)

I keep getting this error:

error[E0308]: mismatched types
  --> src/lib.rs:92:9
   |
88 |     fn column(&self, string: String) -> Series {
   |                                         ------ expected `polars::prelude::Series` because of return type
...
92 |         colin
   |         ^^^^^ expected struct `polars::prelude::Series`, found `&polars::prelude::Series`

For more information about this error, try `rustc --explain E0308`.
error: could not compile `dan` due to previous error

Is there a idiom for doing this deref action?

Any advice much appreciated!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

雨巷深深 2025-02-09 19:20:08

您不能将&系列纳入系列,因为系列不是复制&系列您从self.df.column(& string).unwrap()均由dataframe拥有。

要返回系列,您必须克隆它。不用担心,这是一个超级便宜的克隆,因为系列不过是arc< chunkedarray>,因此克隆只能进行单个原子参考计数操作。

You cannot deref a &Series into Series, because Series is not Copy. The &Series you get from self.df.column(&string).unwrap() is owned by the DataFrame.

To return a Series, you must clone it. Don't worry it is a super cheap clone, because a Series is nothing but an Arc<ChunkedArray>, so the clone only does a single atomic reference count operation.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文