Rust Polars-从DF.Column而不是AN'&&&'获得结构系列。参考
我正在构建一个从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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您不能将
&系列
纳入系列
,因为系列
不是复制
。&系列
您从self.df.column(& string).unwrap()
均由dataframe
拥有。要返回
系列
,您必须克隆它。不用担心,这是一个超级便宜的克隆,因为系列
不过是arc< chunkedarray>
,因此克隆只能进行单个原子参考计数操作。You cannot deref a
&Series
intoSeries
, becauseSeries
is notCopy
. The&Series
you get fromself.df.column(&string).unwrap()
is owned by theDataFrame
.To return a
Series
, you must clone it. Don't worry it is a super cheap clone, because aSeries
is nothing but anArc<ChunkedArray>
, so the clone only does a single atomic reference count operation.