Skip to content

Commit

Permalink
docs(python): improve struct documentation (#11585)
Browse files Browse the repository at this point in the history
  • Loading branch information
romanovacca authored Oct 8, 2023
1 parent c01d599 commit d66ce81
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
8 changes: 4 additions & 4 deletions docs/src/python/user-guide/expressions/structs.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,24 +26,24 @@
# --8<-- [end:struct_unnest]

# --8<-- [start:series_struct]
rating_Series = pl.Series(
rating_series = pl.Series(
"ratings",
[
{"Movie": "Cars", "Theatre": "NE", "Avg_Rating": 4.5},
{"Movie": "Toy Story", "Theatre": "ME", "Avg_Rating": 4.9},
],
)
print(rating_Series)
print(rating_series)
# --8<-- [end:series_struct]

# --8<-- [start:series_struct_extract]
out = rating_Series.struct.field("Movie")
out = rating_series.struct.field("Movie")
print(out)
# --8<-- [end:series_struct_extract]

# --8<-- [start:series_struct_rename]
out = (
rating_Series.to_frame()
rating_series.to_frame()
.select(pl.col("ratings").struct.rename_fields(["Film", "State", "Value"]))
.unnest("ratings")
)
Expand Down
6 changes: 3 additions & 3 deletions docs/user-guide/expressions/structs.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ Polars will interpret a `dict` sent to the `Series` constructor as a `Struct`:

!!! note "Constructing `Series` objects"

Note that `Series` here was constructed with the `name` of the series in the begninng, followed by the `values`. Providing the latter first
Note that `Series` here was constructed with the `name` of the series in the beginning, followed by the `values`. Providing the latter first
is considered an anti-pattern in Polars, and must be avoided.

### Extracting individual values of a `Struct`
Expand All @@ -60,7 +60,7 @@ Let's say that we needed to obtain just the `movie` value in the `Series` that w

### Renaming individual keys of a `Struct`

What if we need to rename individual `field`s of a `Struct` column? We first convert the `rating_Series` object to a `DataFrame` so that we can view the changes easily, and then use the `rename_fields` method:
What if we need to rename individual `field`s of a `Struct` column? We first convert the `rating_series` object to a `DataFrame` so that we can view the changes easily, and then use the `rename_fields` method:

{{code_block('user-guide/expressions/structs','series_struct_rename',['struct.rename_fields'])}}

Expand All @@ -84,7 +84,7 @@ We can identify the unique cases at this level also with `is_unique`!

### Multi-column ranking

Suppose, given that we know there are duplicates, we want to choose which rank gets a higher priority. We define _Count_ of ratings to be more important than the actual `Avg_Rating` themselves, and only use it to break a tie. We can then do:
Suppose, given that we know there are duplicates, we want to choose which rank gets a higher priority. We define `Count` of ratings to be more important than the actual `Avg_Rating` themselves, and only use it to break a tie. We can then do:

{{code_block('user-guide/expressions/structs','struct_ranking',['is_duplicated', 'struct'])}}

Expand Down

0 comments on commit d66ce81

Please sign in to comment.