Estou tentando subdividir um dataframe rust-polars pelos nomes contidos em um frame diferente:
use polars::prelude::*;
fn main() {
let mut df = df! [
"names" => ["a", "b", "c", "d"],
"values" => [1, 2, 3, 4],
"floats" => [1.25, 2., 1., 0.5]
].unwrap();
// println!("{:?}", df);
let mut df1 = df! [
"names" => ["b", "c"],
"values" => [2, 3]
].unwrap();
// println!("original df: {:?}", df1);
let df2 = df
.lazy()
.filter(col("names").is_in(df1.column("names")))
.collect()
.unwrap();
// println!("{:?}", df2);
}
Isso resulta em uma mensagem de erro:
error[E0599]: no method named `is_in` found for enum `Expr` in the current scope
--> src/main.rs:22:30
|
22 | .filter(col("names").is_in(df1.column("names")))
| ^^^^^
|
help: there is a method `is_finite` with a similar name, but with different arguments
--> /home/puller/.cargo/registry/src/index.crates.io-6f17d22bba15001f/polars-plan-0.46.0/src/dsl/mod.rs:781:5
|
781 | pub fn is_finite(self) -> Self {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
For more information about this error, try `rustc --explain E0599`.
error: could not compile `drop_row` (bin "drop_row") due to 1 previous error
Esta página sugere que is_in
"Disponível apenas no recurso de caixa polars-ops". No entanto, adicionar "polars-ops" ao meu Cargo.toml não ajudou:
[dependencies]
polars = {version = "0.46.0", features = ["lazy", "polars-ops"]}
Além disso, a assinatura de is_in
parece diferir daquela discutida nesta questão . Então não está claro se o recurso foi depreciado ou está disponível em outra caixa ou algo mais.
Eu também tentei
let df2 = df
.lazy()
.filter(is_in(col("names"), df1.column("names")))
.collect()
.unwrap();
println!("{:?}", df2);
nesse caso a mensagem de erro é
error[E0425]: cannot find function `is_in` in this scope
--> src/main.rs:30:17
|
30 | .filter(is_in(col("names"), df1.column("names")))
| ^^^^^ not found in this scope
For more information about this error, try `rustc --explain E0425`.
error: could not compile `drop_row` (bin "drop_row") due to 1 previous error
Atualização
Olhando mais cuidadosamente para a ameaça vinculada anteriormente, a assinatura correta é esta , de crate is_in
. A mensagem de erro não é
error[E0277]: the trait bound `Expr: From<&polars::prelude::Column>` is not satisfied
--> src/main.rs:19:36
|
19 | .filter(col("names").is_in(df1.column("names").unwrap()))
| ----- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `From<&polars::prelude::Column>` is not implemented for `Expr`
| |
| required by a bound introduced by this call
|
= help: the following other types implement trait `From<T>`:
`Expr` implements `From<&str>`
`Expr` implements `From<AggExpr>`
`Expr` implements `From<bool>`
`Expr` implements `From<f32>`
`Expr` implements `From<f64>`
`Expr` implements `From<i16>`
`Expr` implements `From<i32>`
`Expr` implements `From<i64>`
and 3 others
= note: required for `&polars::prelude::Column` to implement `Into<Expr>`
note: required by a bound in `polars_plan::dsl::<impl Expr>::is_in`
--> /home/puller/.cargo/registry/src/index.crates.io-6f17d22bba15001f/polars-plan-0.46.0/src/dsl/mod.rs:1190:21
|
1190 | pub fn is_in<E: Into<Expr>>(self, other: E) -> Self {
| ^^^^^^^^^^ required by this bound in `polars_plan::dsl::<impl Expr>::is_in`
For more information about this error, try `rustc --explain E0277`.
error: could not compile `drop_row` (bin "drop_row") due to 1 previous error
Aqui está como você pode fazer isso. Para compilar isso, você deve habilitar
is_in
o recurso noCargo.toml
arquivo. Olit
é usado aqui para criar expressão deSeries
. Isso ocorre porqueis_in
requer que seu argumento seja um tipo de expressão.