Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs(python): add big warnings about using apply #9906

Merged
merged 1 commit into from
Jul 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions py-polars/polars/dataframe/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -5682,6 +5682,10 @@ def apply(
"""
Apply a custom/user-defined function (UDF) over the rows of the DataFrame.

.. warning::
This method is much slower than the native expressions API.
Only use it if you cannot implement your logic otherwise.

The UDF will receive each row as a tuple of values: ``udf(row)``.

Implementing logic using a Python function is almost always _significantly_
Expand Down
4 changes: 4 additions & 0 deletions py-polars/polars/dataframe/groupby.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,10 @@ def apply(self, function: Callable[[DataFrame], DataFrame]) -> DataFrame:
"""
Apply a custom/user-defined function (UDF) over the groups as a sub-DataFrame.

.. warning::
This method is much slower than the native expressions API.
Only use it if you cannot implement your logic otherwise.

Implementing logic using a Python function is almost always _significantly_
slower and more memory intensive than implementing the same logic using
the native expression API because:
Expand Down
4 changes: 4 additions & 0 deletions py-polars/polars/expr/expr.py
Original file line number Diff line number Diff line change
Expand Up @@ -3613,6 +3613,10 @@ def apply(
"""
Apply a custom/user-defined function (UDF) in a GroupBy or Projection context.

.. warning::
This method is much slower than the native expressions API.
Only use it if you cannot implement your logic otherwise.

Depending on the context it has the following behavior:

* Selection
Expand Down
4 changes: 4 additions & 0 deletions py-polars/polars/functions/lazy.py
Original file line number Diff line number Diff line change
Expand Up @@ -1164,6 +1164,10 @@ def apply(
"""
Apply a custom/user-defined function (UDF) in a GroupBy context.

.. warning::
This method is much slower than the native expressions API.
Only use it if you cannot implement your logic otherwise.

Depending on the context it has the following behavior:

* Select
Expand Down
4 changes: 4 additions & 0 deletions py-polars/polars/lazyframe/groupby.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,10 @@ def apply(
"""
Apply a custom/user-defined function (UDF) over the groups as a new DataFrame.

.. warning::
This method is much slower than the native expressions API.
Only use it if you cannot implement your logic otherwise.

Using this is considered an anti-pattern. This will be very slow because:

- it forces the engine to materialize the whole `DataFrames` for the groups.
Expand Down
4 changes: 4 additions & 0 deletions py-polars/polars/series/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -4364,6 +4364,10 @@ def apply(
"""
Apply a custom/user-defined function (UDF) over elements in this Series.

.. warning::
This method is much slower than the native expressions API.
Only use it if you cannot implement your logic otherwise.

If the function returns a different datatype, the return_dtype arg should
be set, otherwise the method will fail.

Expand Down