Skip to content

Commit

Permalink
chore: fix groupby bench (#4384)
Browse files Browse the repository at this point in the history
  • Loading branch information
neeldug committed Aug 18, 2022
1 parent fca8433 commit f379d0c
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 23 deletions.
48 changes: 26 additions & 22 deletions polars/benches/groupby.rs
Original file line number Diff line number Diff line change
@@ -1,28 +1,26 @@
use criterion::{criterion_group, criterion_main, Criterion};
use lazy_static::lazy_static;
use polars::export::once_cell::sync::Lazy;
use polars::prelude::*;
use polars_lazy::dsl::functions::pearson_corr;

lazy_static! {
static ref DATA: DataFrame = {
let path =
std::env::var("CSV_SRC").expect("env var CSV_SRC pointing to the csv_file is not set");
pub static DATA: Lazy<DataFrame> = Lazy::new(|| {
let path =
std::env::var("CSV_SRC").expect("env var CSV_SRC pointing to the csv_file is not set");

let mut df = CsvReader::from_path(&path)
.expect("could not read file")
// 1M rows
.with_n_rows(Some(1000000))
.finish()
.unwrap();
df.try_apply("id1", |s| s.cast(&DataType::Categorical))
.unwrap();
df.try_apply("id2", |s| s.cast(&DataType::Categorical))
.unwrap();
df.try_apply("id3", |s| s.cast(&DataType::Categorical))
.unwrap();
df
};
}
let mut df = CsvReader::from_path(&path)
.expect("could not read file")
// 1M rows
.with_n_rows(Some(1000000))
.finish()
.unwrap();
df.try_apply("id1", |s| s.cast(&DataType::Categorical(None)))
.unwrap();
df.try_apply("id2", |s| s.cast(&DataType::Categorical(None)))
.unwrap();
df.try_apply("id3", |s| s.cast(&DataType::Categorical(None)))
.unwrap();
df
});

fn q1(c: &mut Criterion) {
c.bench_function("groupby q1", |b| {
Expand Down Expand Up @@ -97,7 +95,7 @@ fn q6(c: &mut Criterion) {
.groupby([col("id4"), col("id5")])
.agg([
col("v3").median().alias("v3_median"),
col("v3").std().alias("v3_std"),
col("v3").std(0).alias("v3_std"),
])
.collect()
.unwrap();
Expand Down Expand Up @@ -126,7 +124,13 @@ fn q8(c: &mut Criterion) {
.lazy()
// todo! accept slice of str
.drop_nulls(Some(vec![col("v3")]))
.sort("v3", true)
.sort(
"v3",
SortOptions {
descending: true,
nulls_last: false,
},
)
.groupby([col("id6")])
.agg([col("v3").head(Some(2)).alias("v3_top_2")])
.explode(vec![col("v3_top_2")])
Expand Down
2 changes: 1 addition & 1 deletion polars/polars-lazy/src/dsl/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ mod expr;
mod from;
pub(crate) mod function_expr;
#[cfg(feature = "compile")]
mod functions;
pub mod functions;
#[cfg(feature = "list")]
mod list;
mod options;
Expand Down

0 comments on commit f379d0c

Please sign in to comment.