Skip to content

Commit

Permalink
Remove implementation details from apply docstrings (#10651)
Browse files Browse the repository at this point in the history
Removes some unnecessary implementation detail from `apply` docstrings and updates them where necessary.

Authors:
  - https://github.com/brandon-b-miller

Approvers:
  - GALI PREM SAGAR (https://github.com/galipremsagar)
  - Ashwin Srinath (https://github.com/shwina)

URL: #10651
  • Loading branch information
brandon-b-miller authored Apr 13, 2022
1 parent dd7143a commit c72868e
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 17 deletions.
25 changes: 13 additions & 12 deletions python/cudf/cudf/core/dataframe.py
Original file line number Diff line number Diff line change
Expand Up @@ -3564,12 +3564,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 @@ -3590,7 +3591,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 @@ -3606,7 +3607,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 @@ -3622,7 +3623,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 @@ -3641,7 +3642,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 @@ -3658,7 +3659,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 @@ -3675,7 +3676,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

0 comments on commit c72868e

Please sign in to comment.