Skip to content

Commit

Permalink
docs(python): improve docstring of (Expr|Series).map_elements (#16079)
Browse files Browse the repository at this point in the history
  • Loading branch information
KDruzhkin authored Jun 2, 2024
1 parent b0845e3 commit 40ef36f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
6 changes: 6 additions & 0 deletions py-polars/polars/expr/expr.py
Original file line number Diff line number Diff line change
Expand Up @@ -4866,6 +4866,12 @@ def map_elements(
`pl.col("col_name").sqrt()`.
- For mapping inner elements of lists, consider:
`pl.col("col_name").list.eval(pl.element().sqrt())`.
- For mapping elements of struct fields, consider:
`pl.col("col_name").struct.field("field_name").sqrt()`.
If you want to replace the original column or field,
consider :meth:`.with_columns <polars.DataFrame.with_columns>`
and :meth:`.with_fields <polars.Expr.struct.with_fields>`.
The UDF is applied to each element of a column. Note that, in a GroupBy
context, the column will have been pre-aggregated and so each element
Expand Down
2 changes: 2 additions & 0 deletions py-polars/polars/series/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -5451,6 +5451,8 @@ def map_elements(
- For mapping elements of a series, consider: `s.sqrt()`.
- For mapping inner elements of lists, consider:
`s.list.eval(pl.element().sqrt())`.
- For mapping elements of struct fields, consider:
`s.struct.field("field_name").sqrt()`.
If the function returns a different datatype, the return_dtype arg should
be set, otherwise the method will fail.
Expand Down

0 comments on commit 40ef36f

Please sign in to comment.