pola-rs/r-polars

Why is group_by() output always identically sorted?

Open

#1,409 建立於 2025年7月15日

在 GitHub 查看
 (10 留言) (0 反應) (0 負責人)R (39 fork)github user discovery
bughelp wanted

倉庫指標

Star
 (562 star)
PR 合併指標
 (PR 指標待抓取)

描述

Moved from: https://github.com/eitsupi/neo-r-polars/issues/339


Python polars and old r-polars return dataframes with different row order, but the rewritten polars returns all dataframes identically sorted:

import polars as pl

n_obs = 6
df = pl.LazyFrame({
    "feature": ["b", "b", "c", "c", "a", "a"],
    "value": list(range(n_obs)),
})

for i in range(10):
    print(
        df.group_by("feature").agg([
            pl.col("value").mean(),
        ]).collect()
    )
df = pl$LazyFrame(
    feature = c("b", "b", "c", "c", "a", "a"),
    value = 1:6,
)

for (i in 1:10) {
  print(
    df$group_by("feature")$agg(
      pl$len(),
      pl$col("value")$mean(),
    )$collect()
  )
}

貢獻者指南