0

hi i am trying to remove duplicates based on a column "time" in my dataframe.

i read the official document which defines the unique() method as follows:

pub fn unique(
    &self,
    subset: Option<&[String]>,
    keep: UniqueKeepStrategy,
    slice: Option<(i64, usize)>
) -> PolarsResult<DataFrame>
 

but somehow when i executed :

fn main() -> Result<(), Box<dyn Error>> {
    let col_name = String::from("time");
    let df = read_csv()?.unique(vec![col_name], UniqueKeep::First)?;
    println!("{:?}", df);
    Ok(())
}

i got this error:

error[E0433]: failed to resolve: use of undeclared type `UniqueKeep`
   --> src/main.rs:155:49
    |
155 |     let df = read_csv()?.unique(vec![col_name], UniqueKeep::First)?;
    |                                                 ^^^^^^^^^^ use of undeclared type `UniqueKeep`

could it be some kind of missing import? i only loaded the prelude:

use polars::prelude::*;
Arthur Zhang
  • 107
  • 8
  • The enum is called `UniqueKeepStrategy`, not `UniqueKeep`. – Caesar Jun 08 '23 at 01:19
  • ahh, i see. now it returns `an argument of type Option<(i64, usize)> is missing`, do you know what should i pass to this `slice: Option<(i64, usize)>` parameter ? – Arthur Zhang Jun 08 '23 at 01:24

1 Answers1

1

the enum should be UniqueKeepStrategy, and the slice could be simply 'None'

also: use unique_stable instead to avoid order being meseed up.

Arthur Zhang
  • 107
  • 8
  • Where possible, please don't post screenshots of code or error messages so SO stays searchable and accessible. The mention of the function name (`unique_stable`) would have been sufficient. Also weird: This function is on `LazyFrame`, earlier you were working with `DataFrame`. – Caesar Jun 08 '23 at 05:57