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

Remove implementation details from apply docstrings #10651

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
25 changes: 13 additions & 12 deletions python/cudf/cudf/core/dataframe.py
Original file line number Diff line number Diff line change
Expand Up @@ -3575,12 +3575,13 @@ def apply(
):
"""
Apply a function along an axis of the DataFrame.

Designed to mimic `pandas.DataFrame.apply`. Applies a user
defined function row wise over a dataframe, with true null
handling. Works with UDFs using `core.udf.pipeline.nulludf`
and returns a single series. Uses numba to jit compile the
function to PTX via LLVM.
``apply`` relies on Numba to JIT compile ``func``.
Thus the allowed operations within ``func`` are limited
to the ones specified
[here](https://numba.pydata.org/numba-doc/latest/cuda/cudapysupported.html).
For more information, see the cuDF guide
to user defined functions found
[here](https://docs.rapids.ai/api/cudf/stable/user_guide/guide-to-udfs.html).

Parameters
----------
Expand All @@ -3601,7 +3602,7 @@ def apply(
Examples
--------

Simple function of a single variable which could be NA
Simple function of a single variable which could be NA:

>>> def f(row):
... if row['a'] is cudf.NA:
Expand All @@ -3617,7 +3618,7 @@ def apply(
dtype: int64

Function of multiple variables will operate in
a null aware manner
a null aware manner:

>>> def f(row):
... return row['a'] - row['b']
Expand All @@ -3633,7 +3634,7 @@ def apply(
3 <NA>
dtype: int64

Functions may conditionally return NA as in pandas
Functions may conditionally return NA as in pandas:

>>> def f(row):
... if row['a'] + row['b'] > 3:
Expand All @@ -3652,7 +3653,7 @@ def apply(
dtype: int64

Mixed types are allowed, but will return the common
type, rather than object as in pandas
type, rather than object as in pandas:

>>> def f(row):
... return row['a'] + row['b']
Expand All @@ -3669,7 +3670,7 @@ def apply(

Functions may also return scalar values, however the
result will be promoted to a safe type regardless of
the data
the data:

>>> def f(row):
... if row['a'] > 3:
Expand All @@ -3686,7 +3687,7 @@ def apply(
2 5.0
dtype: float64

Ops against N columns are supported generally
Ops against N columns are supported generally:

>>> def f(row):
... v, w, x, y, z = (
Expand Down
16 changes: 11 additions & 5 deletions python/cudf/cudf/core/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -2021,9 +2021,15 @@ def _return_sentinel_series():
def apply(self, func, convert_dtype=True, args=(), **kwargs):
"""
Apply a scalar function to the values of a Series.
Similar to ``pandas.Series.apply``.

Similar to `pandas.Series.apply. Applies a user
defined function elementwise over a series.
``apply`` relies on Numba to JIT compile ``func``.
Thus the allowed operations within ``func`` are limited
to the ones specified
[here](https://numba.pydata.org/numba-doc/latest/cuda/cudapysupported.html).
For more information, see the cuDF guide to
user defined functions found
[here](https://docs.rapids.ai/api/cudf/stable/user_guide/guide-to-udfs.html).

Parameters
----------
Expand Down Expand Up @@ -2061,7 +2067,7 @@ def apply(self, func, convert_dtype=True, args=(), **kwargs):
2 4
dtype: int64

Apply a basic function to a series with nulls
Apply a basic function to a series with nulls:

>>> sr = cudf.Series([1,cudf.NA,3])
>>> def f(x):
Expand All @@ -2073,7 +2079,7 @@ def apply(self, func, convert_dtype=True, args=(), **kwargs):
dtype: int64

Use a function that does something conditionally,
based on if the value is or is not null
based on if the value is or is not null:

>>> sr = cudf.Series([1,cudf.NA,3])
>>> def f(x):
Expand All @@ -2091,7 +2097,7 @@ def apply(self, func, convert_dtype=True, args=(), **kwargs):
as derived from the UDFs logic. Note that this means
the common type will be returned even if such data
is passed that would not result in any values of that
dtype.
dtype:

>>> sr = cudf.Series([1,cudf.NA,3])
>>> def f(x):
Expand Down