Skip to content

Commit

Permalink
Fix docs again
Browse files Browse the repository at this point in the history
  • Loading branch information
alonme committed Oct 12, 2024
1 parent e0a483a commit 6af3eba
Showing 1 changed file with 28 additions and 13 deletions.
41 changes: 28 additions & 13 deletions py-polars/polars/expr/struct.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,19 +158,34 @@ def unnest(self) -> Expr:
Alias for `Expr.struct.field("*")`.
Examples
--------
>>> df = pl.DataFrame({"nested": [{"a": 1, "b": 2}, {"a": 3, "b": 4}]})
>>> df.select(pl.col("nested").struct.unnest())
shape: (2, 2)
┌─────┬─────┐
│ a │ b │
│ --- │ --- │
│ i64 │ i64 │
╞═════╪═════╡
│ 1 │ 2 │
│ 3 │ 4 │
└─────┴─────┘
>>> df = pl.DataFrame(
... {
... "aaa": [1, 2],
... "bbb": ["ab", "cd"],
... "ccc": [True, None],
... "ddd": [[1, 2], [3]],
... }
... ).select(pl.struct("aaa", "bbb", "ccc", "ddd").alias("struct_col"))
>>> df
shape: (2, 1)
┌──────────────────────┐
│ struct_col │
│ --- │
│ struct[4] │
╞══════════════════════╡
│ {1,"ab",true,[1, 2]} │
│ {2,"cd",null,[3]} │
└──────────────────────┘
>>> df.select(pl.col("struct_col").struct.unnest())
shape: (2, 4)
┌─────┬─────┬──────┬───────────┐
│ aaa ┆ bbb ┆ ccc ┆ ddd │
│ --- ┆ --- ┆ --- ┆ --- │
│ i64 ┆ str ┆ bool ┆ list[i64] │
╞═════╪═════╪══════╪═══════════╡
│ 1 ┆ ab ┆ true ┆ [1, 2] │
│ 2 ┆ cd ┆ null ┆ [3] │
└─────┴─────┴──────┴───────────┘
"""
return self.field("*")

Expand Down

0 comments on commit 6af3eba

Please sign in to comment.