尽管:
安装成功
cargo add polars-lazy
以下代码会导致错误:
错误[E0433]:无法解决:在
legacy
中找不到
arrow
错误[E0433]:无法解决:使用未声明的板条箱或模块
polars_core
错误[E0412]:在此范围内找不到类型
PolarsResult
错误[E0412]:在此范围内找不到类型
DataFrame
use polars_core::prelude::*;
use polars_core::df;
use polars_lazy::prelude::*;
use arrow::legacy::prelude::QuantileMethod;
fn main() {
let test = example()
println!("show dataframe: {:?}", test);
}
fn example() -> PolarsResult<DataFrame> {
let df = df!(
"date" => ["2020-08-21", "2020-08-21", "2020-08-22", "2020-08-23", "2020-08-22"],
"temp" => [20, 10, 7, 9, 1],
"rain" => [0.2, 0.1, 0.3, 0.1, 0.01]
)?;
df.lazy()
.group_by([col("date")])
.agg([
col("rain").min().alias("min_rain"),
col("rain").sum().alias("sum_rain"),
col("rain").quantile(lit(0.5), QuantileMethod::Nearest).alias("median_rain"),
])
.sort(["date"], Default::default())
.collect()
}
注:
Cargo.toml
[dependencies]
arrow = "53.2.0"
polars-lazy = "0.44.2"
要使用
polars_core
,您必须将 polars-core
添加到您的依赖项中。
arrow
是 polars-arrow
的重命名导入:
[dependencies.arrow] default-features = false features = ["compute_aggregate", "compute_arithmetics", "compute_bitwise", "compute_boolean", "compute_boolean_kleene", "compute_cast", "compute_comparison"] package = "polars-arrow" version = "0.44.2"
因此您应该从依赖项中删除
arrow = "53.2.0"
并添加:
polars-core = "0.44.2"
arrow = { version = "0.44.2", package = "polars-arrow" }