pola-rs/r-polars

Why is group_by() output always identically sorted?

Open

#1,409 opened on 2025年7月15日

GitHub で見る
 (10 comments) (0 reactions) (0 assignees)R (39 forks)github user discovery
bughelp wanted

Repository metrics

Stars
 (562 stars)
PR merge metrics
 (PR metrics pending)

説明

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()
  )
}

コントリビューターガイド