Skip to content

Commit

Permalink
rename stable_groupby -> groupby_stable
Browse files Browse the repository at this point in the history
  • Loading branch information
ritchie46 committed Dec 15, 2021
1 parent 0d7555a commit 64d5416
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 15 deletions.
2 changes: 1 addition & 1 deletion polars/polars-lazy/src/frame.rs
Original file line number Diff line number Diff line change
Expand Up @@ -821,7 +821,7 @@ impl LazyFrame {
}

/// Similar to groupby, but order of the DataFrame is maintained.
pub fn stable_groupby<E: AsRef<[Expr]>>(self, by: E) -> LazyGroupBy {
pub fn groupby_stable<E: AsRef<[Expr]>>(self, by: E) -> LazyGroupBy {
let opt_state = self.get_opt_state();
LazyGroupBy {
logical_plan: self.logical_plan,
Expand Down
26 changes: 13 additions & 13 deletions polars/polars-lazy/src/tests/queries.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1643,7 +1643,7 @@ fn test_sort_by() -> Result<()> {
let out = df
.clone()
.lazy()
.stable_groupby([col("b")])
.groupby_stable([col("b")])
.agg([col("a").sort_by([col("b"), col("c")], [false])])
.collect()?;
let a = out.column("a")?.explode()?;
Expand All @@ -1655,7 +1655,7 @@ fn test_sort_by() -> Result<()> {
// evaluate_on_groups
let out = df
.lazy()
.stable_groupby([col("b")])
.groupby_stable([col("b")])
.agg([col("a").sort_by([col("b"), col("c")], [false]).list()])
.collect()?;

Expand Down Expand Up @@ -1950,7 +1950,7 @@ fn test_agg_exprs() -> Result<()> {
// a binary expression followed by a function and an aggregation. See if it runs
let out = df
.lazy()
.stable_groupby([col("cars")])
.groupby_stable([col("cars")])
.agg([(lit(1) - col("A"))
.map(|s| Ok(&s * 2), GetOutput::same_type())
.list()
Expand Down Expand Up @@ -1980,7 +1980,7 @@ fn test_groupby_rank() -> Result<()> {
let df = fruits_cars();
let out = df
.lazy()
.stable_groupby([col("cars")])
.groupby_stable([col("cars")])
.agg([col("B").rank(RankOptions {
method: RankMethod::Dense,
..Default::default()
Expand Down Expand Up @@ -2019,7 +2019,7 @@ fn test_apply_multiple_columns() -> Result<()> {

let out = df
.lazy()
.stable_groupby([col("cars")])
.groupby_stable([col("cars")])
.agg([apply_mul(
multiply,
[col("A"), col("B")],
Expand Down Expand Up @@ -2117,7 +2117,7 @@ fn test_take_consistency() -> Result<()> {
let out = df
.clone()
.lazy()
.stable_groupby([col("cars")])
.groupby_stable([col("cars")])
.agg([col("A").arg_sort(true).take(lit(0))])
.collect()?;

Expand All @@ -2128,7 +2128,7 @@ fn test_take_consistency() -> Result<()> {
let out_df = df
.clone()
.lazy()
.stable_groupby([col("cars")])
.groupby_stable([col("cars")])
.agg([
col("A"),
col("A").arg_sort(true).take(lit(0)).alias("1"),
Expand Down Expand Up @@ -2239,7 +2239,7 @@ fn test_binary_agg_context_0() -> Result<()> {

let out = df
.lazy()
.stable_groupby([col("groups")])
.groupby_stable([col("groups")])
.agg([when(col("vals").first().neq(lit(1)))
.then(lit("a"))
.otherwise(lit("b"))
Expand Down Expand Up @@ -2280,7 +2280,7 @@ fn test_binary_agg_context_1() -> Result<()> {
let out = df
.clone()
.lazy()
.stable_groupby([col("groups")])
.groupby_stable([col("groups")])
.agg([when(col("vals").eq(lit(1)))
.then(col("vals").sum())
.otherwise(lit(90))
Expand All @@ -2301,7 +2301,7 @@ fn test_binary_agg_context_1() -> Result<()> {

let out = df
.lazy()
.stable_groupby([col("groups")])
.groupby_stable([col("groups")])
.agg([when(col("vals").eq(lit(1)))
.then(lit(90))
.otherwise(col("vals").sum())
Expand Down Expand Up @@ -2335,7 +2335,7 @@ fn test_binary_agg_context_2() -> Result<()> {
let out = df
.clone()
.lazy()
.stable_groupby([col("groups")])
.groupby_stable([col("groups")])
.agg([((col("vals").first() - col("vals")).list()).alias("vals")])
.collect()?;

Expand All @@ -2353,7 +2353,7 @@ fn test_binary_agg_context_2() -> Result<()> {
// Same, but now we reverse the lhs / rhs.
let out = df
.lazy()
.stable_groupby([col("groups")])
.groupby_stable([col("groups")])
.agg([((col("vals")) - col("vals").first()).list().alias("vals")])
.collect()?;

Expand Down Expand Up @@ -2428,7 +2428,7 @@ fn test_apply_flatten() -> Result<()> {

let out = df
.lazy()
.stable_groupby([col("B")])
.groupby_stable([col("B")])
.agg([col("A").abs().sum()])
.collect()?;

Expand Down
2 changes: 1 addition & 1 deletion py-polars/src/lazy/dataframe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ impl PyLazyFrame {
let ldf = self.ldf.clone();
let by = py_exprs_to_exprs(by);
let lazy_gb = if maintain_order {
ldf.stable_groupby(by)
ldf.groupby_stable(by)
} else {
ldf.groupby(by)
};
Expand Down

0 comments on commit 64d5416

Please sign in to comment.