Skip to content

Commit

Permalink
docs: Fix aggregation guide discrepancies (#18003)
Browse files Browse the repository at this point in the history
  • Loading branch information
deanm0000 authored Aug 2, 2024
1 parent 04ac815 commit 6d2af37
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 7 deletions.
4 changes: 1 addition & 3 deletions docs/src/python/user-guide/expressions/aggregation.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,9 +160,7 @@ def get_person() -> pl.Expr:
get_person().first().alias("youngest"),
get_person().last().alias("oldest"),
get_person().sort().first().alias("alphabetical_first"),
pl.col("gender")
.sort_by(pl.col("first_name").cast(pl.Categorical("lexical")))
.first(),
pl.col("gender").sort_by(get_person()).first(),
)
.sort("state")
.limit(5)
Expand Down
7 changes: 3 additions & 4 deletions docs/user-guide/expressions/aggregation.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,8 @@ Per GROUP `"first_name"` we
<!-- dprint-ignore-start -->

- count the number of rows in the group:
- short form: `pl.count("party")`
- full form: `pl.col("party").count()`
- aggregate the gender values groups:
- full form: `pl.len()`
- combine the values of gender into a list by omitting an aggregate function:
- full form: `pl.col("gender")`
- get the first value of column `"last_name"` in the group:
- short form: `pl.first("last_name")` (not available in Rust)
Expand Down Expand Up @@ -94,7 +93,7 @@ However, **if** we also want to sort the names alphabetically, this breaks. Luck
--8<-- "python/user-guide/expressions/aggregation.py:sort2"
```

We can even sort by another column in the `group_by` context. If we want to know if the alphabetically sorted name is male or female we could add: `pl.col("gender").sort_by("first_name").first().alias("gender")`
We can even sort by another column in the `group_by` context. If we want to know if the alphabetically sorted name is male or female we could add: `pl.col("gender").sort_by(get_person()).first()`

{{code_block('user-guide/expressions/aggregation','sort3',['group_by'])}}

Expand Down

0 comments on commit 6d2af37

Please sign in to comment.