我想弄清楚为什么示例代码不起作用?
这在我的toml文件中:
polars=">
这是Polars Eagle食谱的样本:
use polars::prelude::*;
fn main() {
let s = Series::new("a", &[1, 2, 3]);
let ca = UInt32Chunked::new("b", &[Some(3), None, Some(1)]);
println!("{:?}", s.eq(2));
println!("{:?}", ca.eq(2));
}
它看起来像";eq";函数未正确过载?!我得到以下错误:
error[E0308]: mismatched types
--> srcmain.rs:7:27
|
7 | println!("{:?}", s.eq(2));
| -- ^ expected `&polars::prelude::Series`, found integer
| |
| arguments to this function are incorrect
|
note: associated function defined here
--> C:Usersrnio.rustuptoolchainsnightly-x86_64-pc-windows-msvclib/rustlib/src/rustlibrarycoresrccmp.rs:228:8
|
228 | fn eq(&self, other: &Rhs) -> bool;
| ^^
error[E0599]: `ChunkedArray<UInt32Type>` is not an iterator
--> srcmain.rs:9:25
|
9 | println!("{:?}", ca.eq(2));
| ^^ `ChunkedArray<UInt32Type>` is not an iterator
|
::: C:Usersrnio.cargoregistrysrcgithub.com-1ecc6299db9ec823polars-core-0.22.7srcchunked_arraymod.rs:143:1
|
143 | pub struct ChunkedArray<T> {
| -------------------------- doesn't satisfy `ChunkedArray<UInt32Type>: Iterator`
|
= note: the following trait bounds were not satisfied:
`ChunkedArray<UInt32Type>: Iterator`
which is required by `&mut ChunkedArray<UInt32Type>: Iterator`
感谢@isaactfa。。。当前的解决方法是在比较之前将Series转换为ChuckedArray。
这是一个工作代码:
use polars::prelude::*;
fn main() {
let s = Series::new("a", &[1, 2, 3]);
let ca = UInt32Chunked::new("b", &[Some(3), None, Some(1)]);
println!("{:?}", s.i32().unwrap().equal(2));
println!("{:?}", ca.equal(3));
}